Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : gniccolai Date : Wed Feb 16 2005 07:01 am David Hopwood wrote in message news:... > Giancarlo Niccolai wrote: > > So, the thing here is not what happens in that COFU, but that there is > > someone saying (and from Mariani sayings, CURRENTLY putting in a > > compiler) THIS scheme: > > > > the_safe_initializer() { > > acquire_mutex() > > if (! cls.initialized) //a classwide static or something the like > > cls.construct() // a classwide constructor or something the like > > release_mutex() > > } > > > > Now, we all know here that THIS may deadlock, even (or especially) if > > applied to correct/legal MT code, as we don't know what > > cls.construct() is doing, and as someone may i.e. legitimaly do: > > > > acquire_recursive_mutex_used_in_cls_constructor() > > the_safe_initializer() > > cls.something = change() > > release_recursive_mutex_used_in_cls_constructor() > > > > and this is just one of the endless *legal* pattern that may bring > > the_safe_initializer() to deadlock. > > How can the program refer to the same mutex that is generated by the > compiler? There is no program variable referring to it. Only the > generated code can refer to it. acquire_recursive_mutex_used_in_cls_constructor() IS NOT REFERRING TO ANY MUTEX GENERATED BY THE COMPILER, but to a recursive mutex used in cls.constructor() for its own internal needs. It's used by the application to do something in cls, not by the compiler. See the previous mail. Bests, Gian. .