Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : Chris Thomasson Date : Fri May 27 2005 04:12 pm >> How many existing processors today could trip the assertion? > > In principle, any of them. There is nothing illegal about the compiler > implementing the CPU A loop as, in pseudo-code: > > shared+=5; > usleep(1); > shared=1; > > It would violate no standard at all. Agreed. > In practice, it is hard to imagine any existing processor compiler > could actually trip that assertion. OK. Lets take "any compiler" out of situation, and just use a pseudo assembly language: word_sized_var_t shared = 0 ; assume the variable shared located at address 0x12345678 ; and "fully initalized to zero" before any CPU executes the loops: CPU A -------- 1: move $0x12345678 into generic register %r1 2: loop: 3: move $1 into variable that (%r1) points to 4: jump to loop CPU B -------- 1: move $0x12345678 intp generic register %r1 2: loop: 3: move contents of (%r1) into generic register %r2 4: compare %r2 with $0 5: jump to loop if equal 6: compare %r2 with $1 7: jump to loop if equal 8: crash! Lets say that the very generic instructions ( move, jump, compare ) and registers ( r1, r2 ) represented assembly language from any processors that exist today, how many of them could actually reach "crash!" in CPU B? .