Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Sat Feb 19 2005 01:49 pm gniccolai@yahoo.com (Giancarlo Niccolai) writes: > I can try to access any variable from any thread in any moment, in C, > in C++, or in any language, and there's nothing in the C++ or posix > standards preventing me from doing it. > > The fact that its initialization may be or may be not already complete > is MINE problem, not the compiler's, not the standard's, but mine alone. C++ standard explicitly says that this has undefined behavior, so you have no right to complain to a C++ compiler vendor that the compiler causes a deadlock in this case. Indeed it's your problem if you rely on undefined behavior and your program starts to misbehave in a different way. Other compilers may follow GCC which in version 4 already makes static locals MT-safe. It can be turned off, but not because it might not work (it doesn't break correct programs): "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." The internal API used by code generated by GCC is described here: http://www.codesourcery.com/cxx-abi/abi.html#once-ctor -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .