Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : Sean Kelly Date : Fri Aug 12 2005 01:57 pm David Schwartz wrote: > > If you have no global memory barriers, you cannot have a function that > "synchronizes memory with respect to other threads". POSIX requires > functions to do this. I disagree. Say I have this program: int i, j; void* thread1(void*) { //do something with i } void* thread2(void*) { //do something with i } Since both threads only access i (and not j), the only memory that POSIX requires to be "synchronized with respect to other threads" is the memory used to store i. This is why the condition that all shared memory access must be serialized via certain functions is so important--it offers markers to aid in determining what data must be synchronized. > > Does it say "all memory"? No, it doesn't. And my interpretation is > > supported > > by the fact that you don't need to synchronize all of memory in order to > > meet > > the 'no data races' requirement. > > If I have three dogs and I ask my daughter to walk the dogs, can she > walk two of them? This is a bad analogy. A more appropriate one might be asking your daughter to walk the dogs that have to pee. If she isn't observant or if the number of dogs is relatively small she may well opt to walk them all just to be safe. But that isn't guaranteed. > Your straining *awfully* hard to get the standard to say what you want. We're arguing semantics and language is terribly inexact. But I think the intent of these sections is to allow a good deal of leeway in the design of systems that may be POSIX-compliant. Sure, every POSIX system you run across might implement mutexes via globally effective hardware memory-barriers, but I don't think that the wording requires this. But as Joe said elsewhere, since the spec is necessarily vague, a programmer must make certain assumptions about implementation if the code he is writing goes beyond the scope of the POSIX standard. > It just says synchronize memory. With no caveats, that means to fully > synchronize all of memory. The caveat was "with respect to other threads." This is fairly vague, but that it's there at all suggests to me that it should not be ignored. Sean .