<b>(a)</b> // Oops - compiler could reorder // writes like this. R = true; for( int i=0; i<n; i++ ) M[i] = ...; <b>(b)</b> // Oops - compiler hoists loop invariant! int t = R; while( t==0 ) continue; for( int i=0; i<n; i++ ) ... = M[i];
Example 2: Compiler that presumes single-thread semantics could transform Example 1 in a way that breaks it. (a) Sender; (b) receiver.