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:58 pm gniccolai@yahoo.com (Giancarlo Niccolai) writes: > Then the problem remain the same as with the mutexes; pthread_once > just atomically initializes some internal mutex, or other blocking > thing, but semantically doesn't move our problem of deadlocking code > that has been safe by itself before... The point is that it has *not* been safe before. Recursive initialization of static locals has never been correct C++. -------- bool done = false; void test(); class C { public: C() { if (!done) { done = true; test(); } } }; void test() { static C x; } int main(void) { test(); } -------- The result (gcc 4): terminate called after throwing an instance of '__gnu_cxx::recursive_init' what(): N9__gnu_cxx14recursive_initE Would you complain to authors of GCC that this doesn't work? I guess I know what they would answer :-) -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .