matthias_buehlmann
matthias_buehlmann

Reputation: 5061

is it well defined which thread calls constructors of thread_local storage?

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

Answers (1)

n. m. could be an AI
n. m. could be an AI

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

Related Questions