shared vs __gshared

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 10 12:58:40 PDT 2013


On Mon, 10 Jun 2013 15:46:27 -0400, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:

> On Monday, June 10, 2013 13:23:26 Steven Schveighoffer wrote:
>> shared was supposed to infer memory barriers, but AFAIK, it doesn't do
>> that. Not sure it ever will.
>
> I believe that things are definitely leaning towards shared not adding  
> memory
> barriers. There _might_ be something that happens with shared that  
> relates to
> the GC in order to be able to facilitate per-thread collection, but at  
> this
> point, I think that it's looking like shared will be almost like const  
> in that
> it's a compile-time only thing enforced by the type system but has no  
> effect at
> runtime (the main difference being that objects created as shared will  
> be in
> shared memory rather than being thread-local - which _would_ be a  
> difference at
> runtime - but aside from that, there may be no difference between shared  
> and
> non-shared at runtime).

Well, I think this should be clarified as "the compiler won't generate  
special runtime code."  Given that shared is a type modifier, run time can  
already take advantage of knowing whether something is shared or not.

For example, appending to unshared arrays avoids taking the GC lock if it  
can append in place.

-Steve


More information about the Digitalmars-d-learn mailing list