Subj : Re: double-checked locking in C To : comp.programming.threads From : Joe Seigh Date : Wed Jul 06 2005 08:51 am Laurent Deniau wrote: > Joe Seigh wrote: >> No. While most processors have dependency orderings, not all do. And >> they're usually not part of the processor's formal memory model so you >> have to be extra careful. And the dependency stuff doesn't provide >> release semantics which is usually where people mess up here, your >> example for instance. > > > I do not undertstand your point. How a processor can assign a value that > it does not know yet? If you refer to the small assembly code as a > proof, I think you are confusing object allocation and object > construction. singletons[i].reference is assigned *after* object is > allocated (value returned by allocator function) and *before* object is > constructed, which is a different point. Most people don't realize that it's not just reads that can be out of order but writes as well. So you need release semantics on the store of the init flag as well as acquire semantics on the load of that flag. There was nothing in your example showing that the initialization stores had to appear in memory before the store to the init flag did. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .