Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Hopwood Date : Wed Feb 16 2005 02:42 am 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. -- David Hopwood .