[PATCH] Removing the static destructor from ManagedStatic.cpp by controlling the allocation and de-allocaation of the mutex.

Chris Bieneman beanz at apple.com
Tue Sep 23 15:55:24 PDT 2014


================
Comment at: lib/Support/ManagedStatic.cpp:30
@@ -29,1 +29,3 @@
+  if (nullptr == ManagedStaticMutex)
+    ManagedStaticMutex = new sys::Mutex();
   return ManagedStaticMutex;
----------------
chandlerc wrote:
> Uh... How is this safe? How does this bootstrap when it is called while acquiring a lock (and thus concurrently without any other synchronization)?
It isn't, but since MSVC doesn't implement thread-safe static local initialization I figured this wasn't any worse off.

Do you have an alternate suggestion? I know in other places in LLVM we avoid the static destructor by just leaking the pointer (which I don't like). I could also static init the pointer, and still control deleting it, but I'm not sure that gets us much.

Thoughts?

http://reviews.llvm.org/D5473






More information about the llvm-commits mailing list