static __gshared struct

Hiemlick Hiemlicker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 1 16:26:19 PDT 2016


On Friday, 1 July 2016 at 23:03:17 UTC, Basile B. wrote:
> On Friday, 1 July 2016 at 22:47:21 UTC, Hiemlick Hiemlicker 
> wrote:
>> what exactly does this do? are all members _gshared?
>
> In this case __gshared is a complete NOOP. __gshared has only 
> an effect on variables. It prevents them to reside in the TLS, 
> so that they can be used by any thread of the program (even if 
> then critical sections or atomic read/write are then necessary).
>
> Static means that the declaration is like if in the global 
> scope:
>
> void main()
> {
>     static struct Foo{}
> }
>
> is like
>
> struct Foo{}
>
> void main(string[] args)
> {}
>
> It's not considered nested anymore.

Ok, Does that mean


> void main()
> {
>     static struct Foo{}
       foo();
> }

void foo()
{
    Foo f;
}

works?

Also, then how do I declare a struct to be "global" so that it 
can be common to all threads? Do I have to declare _gshared for 
each element of the struct?



More information about the Digitalmars-d-learn mailing list