Subj : Re: double-checked locking in C To : comp.programming.threads From : Laurent Deniau Date : Thu Jul 07 2005 02:55 pm Giancarlo Niccolai wrote: > Laurent Deniau wrote: > > >>David Hopwood wrote: > > >>>You're mistaken; processors can reorder memory accesses across jumps. >> >>I was abusively talking of a jump while in fact the goal was to have a >>call. I don't know if processor can do tentative evaluation of a call, >>but the value it has to assigned is returned by value from the call. > > Actually, in parallel architectures it is possible to perform tentative > evaluation of calls. > > However, I would not suggest to rely on such idioms in C, and more notably > in C++, as the compiler may even decide on its own to inline calls, or your I guess that you talk about the linker optimizer. The compiler sees only one translation unit at the same time. > programmers team may turn a function into a macro/inline later on, and you I was explicitly talking of function with *external* linkage. > would end up with a bug that would be deadly difficult to track down. Clear if it happens. > Please notice that I know that what I am saying here is not directly > related with the efficacy of this method, but it's however worth to be > considered when choosing to use this idiom instead of others. As far as I know, there is only three idioms: DCL (not portable) pthread_once (fast) mutex (slow) When I say slow I am talking of a factor 20 comparing to the same semantic without threads. This is a real bottleneck. Do you know portable (C+POSIX) alternatives? Regards, ld. .