Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Giancarlo Niccolai Date : Wed Feb 09 2005 01:43 am Gianni Mariani wrote: > Giancarlo Niccolai wrote: >> Gianni Mariani wrote: >> >> >>>Giancarlo Niccolai wrote: >>>... >>> >>>>Having a reentrant mutex cheching for each initializer initialization 1) >>>>does not fix the generic problem of initialization during static init >>>>with MT already going and 2) would be ... crappy. >>> >>>Why ? Honestly, why would this not solve the problem generically ? >> >> >> Because MUTEXING is not the heart of multithreading!!! You can mutex each >> and every single access to any variable, even from the stack, in all your >> program and still have thread unsafe code!!! >> >> Mutexing the things up won't make your code SAFE. It may make it a little >> bit safer in some cases, but mutexing, although sometimes necessary, is >> rarely enough except in academic cases. >> > > Stick to facts. > > My proposal solves the problem of static locals being initialized in a > generic way - period -. No, it doesn't. Period. Mutexing a static initializer won't make it safe in MT. It solves a class of problems which has been already solved with programming patters. It does not solve all the problems, and make some other problem to arise. THIS is the simple fact, and not an opinion. So, if you advise for this thing being in a compiler, that is, outside the control of the programmer, BE SURE that this is a feature that can be used on request. In example, it may be a keyword as "synchronized", or a #pragma, or even a command line switch. But keep that thing far from my programs, please. (and this is the last reply I send on this topic; including the thread opened by Marcin). Giancarlo. .