Acess variable that was set by thread

ag0aep6g anonymous at example.com
Mon Aug 8 10:17:57 UTC 2022


On Monday, 8 August 2022 at 07:14:33 UTC, vc wrote:
> it seems change it to working is working
>
> ```d
>  __gshared bool zeus;
>  ```
>
> but as I'm new in to D, i will like to hear thoughts even if it 
> works for me

Never ever use `__gshared` ever. It's a glaring safety hole. Use 
`shared` instead.

If you're running into compilation errors with `shared`, that's 
the compiler trying to keep you from shooting your foot off. 
You're supposed to think hard about thread-safety and only then 
cast `shared` away in the right spot.

With `__gshared`, the compiler just pretends that it doesn't see 
that the variable is shared. You're pretty much guaranteed to 
produce race conditions unless you think even harder than you 
would have with `shared`.

By the way, is there some resource that recommends `__gshared` 
over `shared`? It seems that many newbies reach for `__gshared` 
first for some reason.


More information about the Digitalmars-d-learn mailing list