Subj : Re: double-checked locking in C To : comp.programming.threads From : Laurent Deniau Date : Fri Jul 08 2005 11:32 am Chris Friesen wrote: > 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. If find funny to think that cpus meet software standards or OS standards. A cpu is not designed for C neither for POSIX. C and POSIX try to support in their norm most of the hardwares through an abstract machine. CPUs are allowed to do anything as long as it does not change the observable behavior conforming to the assembly instructions semantics. Nothing to do with any software standards. Compilers and OS are allowed to do anything as long as it does not change the observable behavior conforming to the standards. > 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. Agreed. ld. .