Subj : Re: Boost.Threads on its way to C++0x To : comp.programming.threads From : David Hopwood Date : Sat Apr 30 2005 01:40 am gottlobfrege@gmail.com wrote: > Ben Hutchings wrote: >>Peter Dimov wrote: >>> >>>How do you solve the race condition WRT the hidden >>>compiler-generated boolean flag? >> >>You fix it in at the language level. Hans Boehm reported that >>"[t]here appeared to be consensus among those attending the last C++ >>standards meeting that both [synchronised and unsychronised] options >>should be provided to the programmer" >>. > > Yes, it should definitely be optional - you don't want the overhead for > all the cases where you know it is not needed. One of C++'s mantras I > believe... And as wrong-headed in this case as it is in many other cases. The compiler can tell which statics are guaranteed to only be accessed by a single thread (the graph of which functions potentially call each other that is needed to determine this, is also needed for other optimizations). So it can remove any overhead when it is safe to do so -- and it won't make mistakes in determining when this is safe, unlike programmers. The remaining overhead is low, and accesses to initialized statics occur rarely enough in typical programs that it won't have a noticable effect on overall performance anyway. If manual annotations are used for this, it will just be an excuse for compiler implementors not to optimize it properly. -- David Hopwood .