Subj : Re: Memory Barriers, Compiler Optimizations, etc. To : comp.programming.threads From : Joseph Seigh Date : Mon Feb 07 2005 03:53 pm On Mon, 7 Feb 2005 11:41:18 -0800, SenderX wrote: >> > Here are some questions that need clarification in your documentation: >> > >> > 1. Can external data depend on the return value from a failed CAS? >> >> I don't undestand what your asking. > > static CMyData my_data; > static volatile LONG flag = 0; > > > my_data.setup(); > InterlockedCompareExchange( &flag, 1, 0 ); > > > AnotherConcurrentThread > ------------------ > > while ( ! InterlockedCompareExchange( &flag, 0, 0 ) ) { Sleep( 0 ); _asm > pause; } > // flag is set > my_data.use(); > > > > Is this safe? > > while (flag != 1) sleep(0); InterlockedCompareExchange(&flag, 1, 1); would be better. DCL would be a less contrived example of the usage you're trying to show, e.g. initFreeQueue here http://groups-beta.google.com/group/comp.programming.threads/msg/31803c3398658e06 Microsoft should just say that their synchronization functions "synchronize" memory and not bother to define memory synchronization which Posix doesn't bother to define either. :) -- Joe Seigh .