d2 - Thread-local storage variables in D, confusion about interaction with module initializers -


let's have globals , thread-local variables getting initialized (say, tls a, global b, tls c, , global d initialized in order) in module's static this() , deinitialized in static ~this().

could please walk me through steps taken program initialize variables in both single , multi-threaded applications?

or correct me if i'm making really horrible assumption?

edit: make little clearer:

module mymodule; int a; __gshared int b; int c; __gshared d; static this() {   = 2; b = 3; c = 4; d = 1337; } static ~this() {   if(a == 2)     dosomefunc(b);   // , other nonsensical things involve branching on tls , using globals. } 

what happens when change value of in thread spawned, never touch in main thread? dosomefunc() ever called? actual behavior supposed here, , behavior dependent on? how module initializers called regards tls? called once , tls vars shaft beyond value initialization? in world 2 (de)initializers mean?

there 2 types of static constructors:

static this() { ... } 

which gets run whenever new thread started. it's purpose initialize thread local storage (tls) variables.

shares static this() { ... } 

runs once on program startup, , used initialize __gshared , other global data.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -