Subj : Re: double-checked locking in C To : comp.programming.threads From : Laurent Deniau Date : Fri Jul 08 2005 01:43 pm Alexander Terekhov wrote: > Laurent Deniau wrote: > [...] > >>Right. Comming back to the example, returning from a function is a >>sequence point. > > > "The C standard says that it must look that way from the point of > view of the abstract machine defined by the standard. But the as-if Right. > rule says that things can be arbitrarily reordered as long as nobody > can tell. Right. > Since the standard says nothing about threading, it does > not concern itself with statement reorderings that are as-if-safe > under one thread of control but as-if-unsafe under multiple threads > of control." The as-if rule is an implementation-defined problem. The as-if-safe rule becomes an as-if-unsafe rule because of some changes in the context of execution which is not considered by the implementation (e.g. switching off the computer). Unless specified, this is leading to an undefined behavior. Imagine that the implementation of volatile includes memory barrier or some cache synchronisation mechanism (nothing in the C says to not do so), it would still be conform with and without thread. But at the price of hidden penalties that C programmers do not want to hear about. regards, ld. .