In the code below will read1
be always equal to read2
, provided property Flag
can be changed from other threads? Concern here is that
To sum up the other replies, in this situation, what happens to the values of the two variables after the code is executed can't be predicted. Both because the CLR and compiler are largely black boxes to us, and because any sort of prediction regarding the outcome of a race condition is really a gamble that's bound to be wrong at some point.
Regardless, you cannot write code of this sort in a multi-threaded environment.