Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Wed Feb 16 2005 04:49 pm gniccolai@yahoo.com (Giancarlo Niccolai) writes: >> It may not reenter the_safe_initializer. Reentering a static local >> initializer before its previous run has finished is forbidden by the >> C++ standard. > > There is no reason why I may not lock a mutex before entering a > function (constructor or anything) that uses it as well (provided it > is reentrant). You may lock the reentrant mutex again, but you may not enter the static local initializer again. Since a deadlock caused by a mutex around static initializer could happen only if you enter the local initializer again, it never happens in code which isn't already broken. > The above pattern usage is correct, under any standard, and an > automated mutex locking done under the nose of the developer would > break it. It does not break it. Please show me the real code, not pseudocode. The compiler doesn't insert locking around calling functions; it inserts them around dynamic initialization of static locals. I don't see a static local in your code. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .