Otherwise 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 the initialization exits by throwing an exception, the initialization is not complete, so it will be tried again the next time control enters the declaration. If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization.88 If control re-enters the declaration recursively while the variable is being initialized, the behavior is undefined.
脚注88) The implementation must not introduce any deadlock around execution of the initializer.
- The compiler now uses the library interface specified by the C++ ABI for thread-safe initialization of function-scope static variables. Most users should leave this alone, but embedded programmers may want to disable this by specifying -fno-threadsafe-statics for a small savings in code size.
2015-05-01追記：Visual Studio 2015 RCにてThread-safe "magic" staticsをサポート。
Assigning a value to a static local variable in a multithreaded application is not thread safe and we do not recommend it as a programming practice.