Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Wed Feb 09 2005 12:32 pm "Marcin 'Qrczak' Kowalczyk" wrote in message news:878y5x8oof.fsf@qrnik.zagroda... > "David Schwartz" writes: >>> 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. > Since the C++ standard doesn't say about threads, and POSIX doesn't > say about C++, we are already outside their current scopes. Agreed on both points. > We are talking about what a future C++ with threads, or a future POSIX > with C++, should say. Ahh, okay. So long as we're talking about a future standard that integrates threads with C++, it is perfectly reasonable to specify some exact way in which static initializations are to be made thread safe. IMO, the best way to do this would be with a new language keyword. The keyword should simply specify that a particular static be initialized at startup, rather than lazily. This has the advantage of removing overhead rather than adding it. DS .