Subj : Re: double-checked locking in C To : comp.programming.threads From : Chris Friesen Date : Thu Jul 07 2005 05:16 pm Markus Elfring wrote: >>You're mistaken; processors can reorder memory accesses across jumps. > > > Would anybody like to point to the possible reorderings that are described in a CPU > design manual? > How much does it have in common with the technique "out-of-order execution"? We could, but it doesn't matter. CPUs are allowed to do *ANYTHING* as long as it meets the standard. Consider a hypothetical cpu that does everything it can to screw up programs which are not written to the POSIX standard: It's a multi-cpu box with no cache coherence. Data is modified in local cache, and random bits of it get written to main memory. When you release the lock, then main memory is updated. Random bits of main memory are read into the local cache, but when you aquire an appropriate lock the local cache gets updated. Without assembly language memory barriers, it's impossible for DCL to work on such a system. For portability, code should be written to comply to POSIX, full stop. If POSIX doesn't guarantee a behaviour, you can't rely on it. Chris .