Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Olivier Huet Date : Wed Jan 19 2005 01:12 am Hello, Marcin 'Qrczak' Kowalczyk a écrit : > Olivier Huet writes: > >>And if it does, what kind of lock : process wide (for multiple >>threads that access the variable), system wide (for multiple process >>that access the variable), etc etc. ? > > > Depending on whether the variable is process wide or system wide. Yes, but generally, the compiler itself doesn't know it : in a lot of couples compiler+OS, variables are done "system wide" with some OS calls : shared memory, memory file mapping etc. And the compiler can't know it. So it will generate a simple process wide locking, and you will do your system wide locking on the top of it : that can eventually introduce some dead locks... It's hypotetical, but it could be a problem, with that kind of "automatic" locking. > > Generally I tend to associate implicit locks with global objects > (singletons) and explicit locks with local, "anonymous" objects. > Yes I agree with it, and in my singletons classes, I generally lock initialization inside the class, so it "looks like" implicit locks on the external way. BUT, automatic is sometimes problematic : at least, implicit locking by a compiler should be overridable. And it would perhaps be better with the contrary : no locking by default, and locking with language extensions. But I'm not sure of which is the best. Olivier Huet .