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

David Majnemer david.majnemer at gmail.com
Thu Oct 23 18:05:40 PDT 2014


>>! In D5922#10, @beanz wrote:
> It sounds like David's complaints are performance related not correctness.

I'm afraid not.  Because your implementation uses operations which are not atomic, it has undefined behavior in the eyes of C++11.

C++11 [intro.multithread]p21:
The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one of which is not atomic, and neither happens before the other. Any such data race results in undefined behavior.

> Unfortunately his suggested implementation doesn't really cover the needs for this. The hand-rolled solution is basically filling in on Windows where we aren't guaranteed to have <mutex>, <thread>, or <atomic>.

Is there a platform where we can't use <atomic>? I'm aware of platforms where we cannot use <thread> or <mutex> but we should use <atomic> if we can.  My call_once implementation only used <thread> for yield; if we removed it, we wouldn't need anything other than <atomic>.

http://reviews.llvm.org/D5922






More information about the llvm-commits mailing list