[PATCH] Removing the static initializer in ManagedStatic.cpp by using llvm_call_once to initialize the ManagedStatic mutex.

Reid Kleckner rnk at google.com
Thu Oct 30 11:17:51 PDT 2014


I don't think it's that safe.

First, if someone accesses a ManagedStatic before main (this happens today,
right?), then we have no guarantee that the flag has been initialized
because initialization order of globals is arbitrary. The global will start
out zero, but then it will be re-zeroed out later and we'll get double
initialization. =(

Second, it's hard to ensure that all callers actually use global statics
instead of static locals.

BTW, MSVC 14 *also* uses "= default" for std::atomic's default constructor,
which solves the problem with the std::atomic double checked locking
approach.

http://reviews.llvm.org/D5922






More information about the llvm-commits mailing list