philip correctly points out that local static init from constants isn't thread-safe, and we shouldn't rely on the compiler moving variables to BSS if their constant initializer is 0.

This was SVN commit r7055.
This commit is contained in:
janwas
2009-07-31 17:48:45 +00:00
parent 468a67d18c
commit acb9658f81
+6 -1
View File
@@ -215,7 +215,12 @@ LibError debug_WriteCrashlog(const wchar_t* text)
BUSY,
FAILED
};
static volatile uintptr_t state = IDLE;
// note: the initial state is IDLE. we rely on zero-init because
// initializing local static objects from constants may happen when
// this is first called, which isn't thread-safe. (see C++ 6.7.4)
cassert(IDLE == 0);
static volatile uintptr_t state;
if(!cpu_CAS(&state, IDLE, BUSY))
return ERR::REENTERED; // NOWARN