Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Sat Feb 05 2005 03:09 am "David Schwartz" writes: > 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? One lock per a contiguous block of static locals. It could also be one lock per static local, the above is an optimization. > The problem is that you are trying to hide from the programmer > exactly when the initialization takes place, Static locals should only be used in cases when it doesn't matter. > and this will never work right if the initialization does anything > non-trivial. This is not true. > 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? Sometimes I need, sometimes I don't. Anyway, making static locals thread-unsafe by default doesn't help in making the code correct. > 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. This is totally unconvincing. I have never seen a case which would be broken by thread-aware semantics of initialization of static locals. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .