Is local static variable initialization thread-safe in C++11? [duplicate]

The relevant section 6.7:

such a variable is initialized the first time control passes through its declaration; such a variable is considered initialized upon the completion of its initialization. […] If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization.

Then there’s a footnote:

The implementation must not introduce any deadlock around execution of the initializer.

So yes, you’re safe.

(This says nothing of course about the subsequent access to the variable through the reference.)

Leave a Comment