Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Wed Feb 09 2005 12:06 pm Giancarlo Niccolai writes: > Mutexing a static initializer won't make it safe in MT. Sometimes it will, sometimes it will not. What is important that it will not make unsafe any program which was previously safe. > It solves a class of problems which has been already solved with > programming patters. This can be said about any language feature which can be emulated using other features. It's not a reason to reject it. > It does not solve all the problems, Nobody claims that it solves all problems. It solves one important problem though: it allows writing libraries which use local static variables in a MT-safe way, without bringing a dependency on threading libraries. They are portable C++, and they also work with a multithreaded C++ with the proposed semantics of local static variables. > and make some other problem to arise. Wrong. This would be a reason to reject it, but it's not true. If it caused a deadlock, the program would have to enter initialization of a particular local static variable before the previous initialization of that variable finished. But with the traditional non-thread-aware implementation of local static initializers this has undefined behavior. So it doesn't break anything which wasn't already broken. > 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. There is no program which will become broken by this change, so there is no reason to make it conditional. I have asked you to show such program, and you were unable to do it. The paragraph above, about deadlocks, shows that it's impossible. You cannot observe that the change has been made without invoking undefined behavior. > (and this is the last reply I send on this topic; including the thread > opened by Marcin). A great way to avoid admitting an error. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .