Subj : Re: Memory visibility with Pthreads To : comp.programming.threads From : Alexander Terekhov Date : Thu Aug 11 2005 01:50 pm Christoph Bartoschek wrote: > > Alexander Terekhov wrote: > > > > > The standard doesn't say "fully". Certain functions merely "synchronize > > memory" and only as long as the program is data race-free. Very relaxed > > memory models like RCpc are fully compatible with Pthreads. > > How does the "synchronize memory" instead of "fully" apply to my example in > the first post? : int A = 0; : int B = 0; : : Thread 1 executes the following code: : : A = 10; : pthread_mutex_lock(mutex); : B = 10; : pthread_mutex_unlock(mutex); : : Thread 2 executes another codesequence: : : pthread_mutex_lock(mutex); : if (B == 10) { : printf("The value of A is %d\n", A); : } else { : printf("B is not 10\n"); : } : pthread_mutex_unlock(mutex); > Does it become invalid? No. > And is the programm data race-free? Maybe. Provided that thread 1 can execute "A = 10; ..." code only once... and also watch out implementation-specific "memory location" granularity. > I guess it is, because there is no possiblity that one thread writes to a > variable and the other one tries to access it. I meant: http://tinyurl.com/77hvz regards, alexander. .