Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Thu Feb 03 2005 02:13 am "Gianni Mariani" wrote in message news:B6GdnRWW98G7A5zfRVn-2w@speakeasy.net... > 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. Your code is not portable. It relies on slippery and complex semantics that may or may not be available on future processors. There has been a major effort not to heap features onto C or C++ that require specific intricate platform details to be supportable. C and C++ are supposed to run on elevator controllers, remember? The big problem is that you have no way of knowing what optimizations might be possible (and vital) in the future and what will be able to do those optimizations. It may not be just the compiler and the processor, it may be the memory hardware. To design a language feature around things that just happen to work on particular platforms today is just terribly bad practice, and had it been followed in the early days, C would be a dead language today. If you want to make C and C++ support threads, then support threading primitives and don't add language features that can't be implemented with the primitives you support. And for the love of god, don't rely upon code that nobody can understand. DS .