Subj : Re: Memory visibility with Pthreads To : comp.programming.threads From : Maciej Sobczak Date : Thu Aug 11 2005 05:47 pm Maciej Sobczak wrote: > Yes, but my question was considering the situation when *both* threads > *use* functions that synchronize memory. I asked what that > synchronization means with respect to assignments that are performed > *outside* of the critical section made by locking and unlocking a mutex. > If they are guaranteed to be visible as if they were in the same > sequence as they appear in code, then fine. If they are not, then that's > fine as well - but which is true is exactly what I was asking about. After following the link given by Alexander in other post (http://tinyurl.com/77hvz) I've seen that the visibility of data modification between two threads is guaranteed when the modification in one thread is followed by unlock, followed by lock (in the other thread), followed by data read. It is the unlock+lock pair (unlock in one thread and lock in the other) that provides the visibility, not just any of those functions in separation. This means that the platform is allowed to reorder the first thread 1 from this (the original version): A = 10; lock B = 10; unlock to this (because it does not change anything from the point of view of any thread): lock A = 10; B = 10; unlock but *not* to this: lock B = 10; unlock A = 10; It also means that the OP's code is guaranteed to work as expected. I hope I got it right. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .