Semantics of shared

Jason House jason.james.house at gmail.com
Thu May 14 06:00:18 PDT 2009


Matt Wrote:

> Matt Wrote:
> 
> > Is there some way to cast shared to thread local when a local has been acquired?
> 
> It occurs to me that your plan is probably: with an explicit cast when the lock is acquired.   So in practice 'unshared' is really going to mean something more like 'exclusively owned' and these modifiers aren't really going to help with managing what data is actually thread local vs. in the global heap.  The purpose of the 'shared' annotation is then just to warn you about unlocked data and to serve a similar purpose as 'volatile' for code generation.
> 
> Is this about right?

I don't think so. What happens when the lock is released? Any residual use of the cast data is going to be incorrect (lacks a lock). What that means is that the cast is unsafe even when the data is locked! Casting is a back door that should be used with extreme care.



More information about the Digitalmars-d mailing list