Subj : Re: Avoiding synchronization (pthreads) To : comp.programming.threads From : Joe Seigh Date : Wed Mar 02 2005 05:54 pm On Wed, 02 Mar 2005 22:58:32 +0100, Marcin 'Qrczak' Kowalczyk wrote: > "Joe Seigh" writes: > >>> Yes. Are there architectures where one thread decrementing an int can >>> cause another thread which doesn't use a memory barrier see the value >>> which has nothing to do with the actual range of values of this int? >> >> You need the barrier to prevent reads of the shared data occuring before >> the fetch of the count. You only need to do it once after seeing the >> count go to one thread. Kind of like DCL but with multiple initializers. > > Ah, I think I understand. > > I fixed the code to have a cache of this variable accessed outside the > mutex by a single thread, updated from the real variable inside the mutex. > As long as it's only updated by the thread that will access it outside the mutex, then you should be ok. -- Joe Seigh .