Subj : Re: Memory visibility with Pthreads To : comp.programming.threads From : Maciej Sobczak Date : Mon Aug 15 2005 11:12 am Peter Dimov wrote: >>lock >>A = 10; >>B = 10; >>unlock > > and this: > > lock > B = 10; > A = 10; > unlock Of course, but the point was to ensure what is the meaning of lock and unlock in this context. From the visibility point of view, anything that happens *between two consecutive calls* to any synchronization functions cannot be relied upon with regard to their order - from the point of view of other threads, the two versions above make no difference, or at least no other thread should expect and rely on any. Even worse - it is not even sure whether there are two stores or maybe just only one (think of A and B being "neighbours" within what could be stored as a single longer "word"). That's why my concern was only whether the assignment to A happens "before" or "after" lock. And since lock itself does not influence the visibility of A in other threads, then the assignment to A can be moved into the critical section without disrupting anything that is otherwise guaranteed. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .