Semantics of shared

Matt gelfmrogen at yahoo.com
Thu May 14 03:54:22 PDT 2009


Walter Bright Wrote:

> Robert Jacques wrote:
> > I don't see a place for "maybe shared" that isn't already handled by 
> > simply "shared".
> 
> I gave a flip and incomplete answer there.
> 
> I'm not sure there is even a point to a function that could handle both 
> shared and unshared with the same code. [...]
> You're going to want to approach manipulating shared data differently 
> than unshared.

Ok, so there is no cast from 'shared' to 'not shared' or vice-versa, so it's sound.  Sorry, quotes like the above from Robert confused me.

But now I'm confused by the idea that you wouldn't want to use the same code on shared and unshared data.  The usual approach in C or C++ in dealing with shared data is to first acquire a lock and then to run code that would have been otherwise safe on the data.  Is there some way to cast shared to thread local when a local has been acquired?

>  Can you imagine two threads trying to sort the same array?

Not at the same time, but yes.




More information about the Digitalmars-d mailing list