Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Gianni Mariani Date : Wed Feb 02 2005 07:44 pm Giancarlo Niccolai wrote: > Gianni Mariani wrote: .... > But adding a mutex lock/unlock with potential useless context swap at each > object access (because each object access should enter that call and make > the comp already_initialized,0 atomic), even if i.e. you just wanted to > read it, or you had to synchronize it afterwards on YOUR rules, it's more > than silly: it's mad. Especially if you can do it right without it, and > believe me, you can. I'm not sure how the GCC compiler implemented this, but I did show some code that requires a mutex check only on the first time throught the code, otherwise there is no check at all. C++ already checks for prior construction on every pass through the code, this check can be used to also eliminate the need to lock a mutex. The net effect is virtually 0 overhead. .