Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : Joe Seigh Date : Mon Aug 01 2005 07:16 pm David Schwartz wrote: > "David Hopwood" wrote in message > news:1CwHe.6711$GO1.5036@fe3.news.blueyonder.co.uk... > > >>David Schwartz wrote: > > >>> Mutexes only protect memory access that occur while the mutex is held. > > >>Chapter and verse, please. > > >>(Yes, the suggested memory_barrier() does not work. I'm just nitpicking >>about >>the reason why it doesn't work, and whether what POSIX actually says >>allows >>you to infer the statement above.) > > > My copy of the standard is on a high shelf and my ladder is outside, but > it's the section that says that what happens if memory is read by one thread > after being modified by another is undefined unless you follow one of the > patterns specifically stated. The offered technique is not one of the ones > stated. The only one involving mutexes says that you must hold the same > mutex under which the changing thread held after the change was made. > You mean the section that says "Formal definitions of the memory model were rejected as unreadable by the vast majority of programmers. In addition, most of the formal work in the literature has concentrated on the memory as provided by the hardware as opposed to the application programmer through the compiler and runtime system. It was believed that a simple statement intuitive to most programmers would be most effective. IEEE Std 1003.1-2001 defines functions that can be used to synchronize access to memory, but it leaves open exactly how one relates those functions to the semantics of each function as specified elsewhere in IEEE Std 1003.1-2001. IEEE Std 1003.1-2001 also does not make a formal specification of the partial ordering in time that the functions can impose, as that is implied in the description of the semantics of each function. It simply states that the programmer has to ensure that modifications do not occur "simultaneously" with other access to a memory location." Just make sure you don't transgress the unwritten rule. :) -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .