In the code below will read1
be always equal to read2
, provided property Flag
can be changed from other threads? Concern here is that
Yes it can be changed naturally.
Even in the code provided it's not guranteed that read1
would be equal to read2
.
Considering that meanwhile /* some more code */
executed, Flag
can be affected by other threads.
EDIT
The equality of read1
and read2
has nothing to do with inlining or not, Flag
is a bool
, so it's a value type. So
var read1 = Flag;
//let's say read1 TRUEFlag = False
var read2 = Flag;
//read2 is FALSE, but read1 remains TRUEThis is valid in non multithreaded environment too, cause you operating on value type.
If this is not what you're asking for, please clarify.