Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Gianni Mariani Date : Sun Feb 13 2005 09:18 am David Schwartz wrote: > "Gianni Mariani" wrote in message > news:kNCdnWBwbqDJ7pPfRVn-pA@speakeasy.net... > > I can't follow Gianni Mariana's points at all. If the COFU has already > been initialized, the COFU code reduces to: > > acquire_mutex(); > if(false) initialize_object(); > release_mutex(); I can't see why acquire_mutex()/release_mutex() does anything, why have this discussion ? You can't, in general, call all your local static constructors before main() (or before a threads start) is called. e.g. void Method( T1 & v1 ) { static T2 v2( v1 ); } If v1 is a paramater that is only known after threads start, how can you possibly construct v2 before threads are started ? In many cases, you don't know where a local static is used. It could be used in libraries that you don't control. There may also be instances of templates you really don't have control over. I think it's impractical to impose the requirement you suggest. .