Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Wed Feb 09 2005 11:40 am "Marcin 'Qrczak' Kowalczyk" wrote in message news:87mzudd309.fsf@qrnik.zagroda... >> It is perfectly legal for code inside the constructor to dispatch >> another thread and for that other thread to call functions which >> invoke static initializers. > And this is not a problem: each block of initializers have a different > pthread_once_t. There would be a deadlock only if the same initializer > is reentered, but C++ already makes this undefined. POSIX-compliant threads code must already protect these accesses with mutexes or the code is undefined anyway. So how does an additional mutex help? You would have to change either the POSIX standard or the C++ standard. The C++ standard allows lazy initialization. The POSIX standards requires mutexes where objects that are potentially accessed concurrently by another thread may be modified. So C++/POSIX code *must* already contain these mutexes or its behavior is undefined *anyway*. DS .