[DGD] Why export data structures?

Dread Quixadhal quixadhal at chartermi.net
Thu Jun 23 01:03:01 CEST 2005


Petter Nyström wrote:

> This is really just a question out of curiousity. I was thinking of 
> coding something that relied on several objects having access to the 
> same data structure - in this case a mapping. But then I learned that 
> such data structures are made into individual copies in all objects 
> referencing it at the end of the execution thread. So as I understand 
> it, the objects would no longer be referencing the same data in later 
> threads.
>
> Now, I have no reason to be upset why it works like this. I am merely 
> being curious as to the reasons. Why does DGD do this? If someone's 
> got the time to satiate my curiousity, I'd be happy!
>
Not being an expert by any means, I'll make a guess just to see if 
someone more knowledgeable will correct me. :)

My guess would be that it has to do with two features of the driver in 
particular.  First, it would make life much simpler for multi-processor 
support if every thread could have distinct data segments that didn't 
rely on conflicting access with other threads.  When those threads are 
running concurrently, there are all sorts of locking techniques you need 
to use if they can touch the same bits of data.

Secondly, it seems like having separate copies of each thread's data 
structures would make atomic function roll-back considerably simpler.  
If thread N calls a function that fails and gets rolled back, it doesn't 
have to then also mark threads O..Z as "dirty" since they all still have 
their own data which might (or might not) work for them.

To satisfy my own curiosity, is it actually always copied, or is it 
copy-on-write?  IE:  If two threads both start with the same (statically 
declared and filled?) array, and both read from it but don't modify it, 
do we have two copies in memory, or just one with two pointers?



More information about the DGD mailing list