Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : Uenal Mutlu Date : Sat May 21 2005 12:48 pm "David Schwartz" wrote > > "Uenal Mutlu" wrote in message > > > Wrong. All the effort is because it IS shared! If yo don't see it then I'm > > sorry for you: > > > > thread1: > > sets the shared condition variable. > > > > thread2: > > sets the shared condition variable. > > > > thread3: > > waits for the shared condition variable to have a specific value. > > > > Do you now understand that it is shared by multiple threads? > > The variable could also be set to any other value but just the 0 and 1. > > Show me in code how you wait for a condition variable without unsharing > it. By "unsharing it", I mean making it no longer shared in the CPU's cache. I've shown that already, see prev. posting. There is nothing special to do by the user about it. It is sufficient just to use the InterLockedXXX funcs to set and get the atomic variable. Requirements for a variable to be used by InterlockedXXX (on x86, MSVC compiler), is that it must be volatile and right aligned, and of size of the natural word size of the CPU: here 32 bit integer on 32 bit CPUs: // a right aligned 32 bit integer on x86 (MSVC code): #pragma pack(push, 4) volatile long lVar; #pragma pack(pop) Of course such things are best packed (hidden) inside a handy class in C++. .