Subj : Re: posix and lock-free algorithms To : comp.programming.threads From : David Schwartz Date : Fri Aug 12 2005 03:06 pm "Sean Kelly" wrote in message news:1123877121.274302.229340@g44g2000cwa.googlegroups.com... > True enough. But does this matter so far as the POSIX spec is > concerned? ie. I may know that this will work: > > int i, j; > > void* thread1(void*) { > j = 1; > // acquire mutex M > i = 2; > // release mutex M > } > > void* thread2(void*) { > // acquire mutex M > if( i == 2 ) assert( j == 1 ); > // release mutex M > } > > ie. the store for j must occur before the release of M in thread1. But > the spec says nothing about this, correct? Everything would break if this was not the case. For example, a common pattern is to create an object, initialize it, acquire a lock, and add a pointer to that object so other threads can see it, then release the lock. This is why POSIX says that the mutex functions must synchronize memory. DS .