Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : SenderX Date : Fri Feb 04 2005 06:43 pm > If they are mutable, then operations which change them need > synchronization *in adition to* initialization. > If they are mutable, then operations which change them need > synchronization *in adition to* initialization. > > > and/or need thread-safe init provided by implementation to > > begin with. > > If they are initialized lazily and this may happen from multiple > thread simultaneously, then synchronization is needed. Well, "exactly" what kind of sync schema are you getting at here? Are you doing the "extremely slow version" where every access needs to lock a mutex? void blah( ... ) { static whatever something; { // internal init time pseudo-code hashed_cppimpl_mutex_lock( &something ); if ( something_is_not_ready ) { cppimpl_ctor( &something ); swing_to_something_is_ready_state( &something ); } hashed_cppimpl_mutex_unlock( &something ); } something.please_work(); } Note, it would have to work this way on a UP as well. I would want to keep this stuff out of the compiler. I can code thread-safe init once algo's myself it assembly. Then abstract it away in a single API. ;) >Otherwise it's harmless. ^^^^^^^^^^^^^^^^^^^^ If your schema does not follow the "extremely painfully slow" version, then your statement is usually ( its a bit race-condition so things might work for a while... :) wrong and the compiler would need a memory visibility model... .