Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Fri Feb 04 2005 04:54 pm "Marcin 'Qrczak' Kowalczyk" wrote in message news:878y63n8z3.fsf@qrnik.zagroda... > I'm saying that you are wrong, and this kind of locking doesn't get > in the way - sometimes it helps, sometimes it doesn't help, but it > never makes things worse except efficiency. > > I will happily admit my error if there is indeed some non-perverse > code which is being broken by this semantics of local static > initialization. You have been unable to show sketch such code, and > I can't imagine how it may look, so I claim that it doesn't exist > until it's shown otherwise. What precisely are you proposing? That every single instance of a local static have its own lock just to protect its initialization? Or are you suggesting one lock for all of them? The problem is that you are trying to hide from the programmer exactly when the initialization takes place, and this will never work right if the initialization does anything non-trivial. In multithreaded code, when a function is called, you need to understand thoroughly the context in which you call it. What locks are held? What priority is the thread at? You can't fix this automatically, it's just too complex a problem. The details of any proposal I have ever seen so far have broken horribly in totally sensible cases. DS .