Reputation: 5061
does the c++ standard define how, when and by which thread the constructors of thread_local variables are called? Is it for example always the thread itself for which the thread_local data is allocated? or maybe it's the thread that spawns the new thread? or the first thread of the process? or maybe it's up to the compiler?
Upvotes: 2
Views: 278
Reputation: 119877
[basic.start.dynamic] It is implementation-defined whether the dynamic initialization of a non-local non-inline variable with thread storage duration is sequenced before the first statement of the initial function of a thread or is deferred. If it is deferred, the initialization associated with the entity for thread t is sequenced before the first non-initialization odr-use by t of any non-inline variable with thread storage duration defined in the same translation unit as the variable to be initialized. It is implementation-defined in which threads and at which points in the program such deferred dynamic initialization occurs.
Upvotes: 3