How does D lang handle multithreaded applications and static members of classes?

Inkrementator invalid at invalid.org
Wed Apr 2 08:33:05 UTC 2025


On Tuesday, 1 April 2025 at 23:01:23 UTC, Daniel Donnelly, Jr. 
wrote:
> Say I have a static context stack in my class Context, will 
> each new thread receive their own copy of the static member or 
> do I have to account for multiple threads and do it myself?

All global variables in D, including static class members, are 
thread local by default. You have to explicitly add the 
`__gshared` attribute to the static variable to make it truly 
global.


More information about the Digitalmars-d-learn mailing list