In the code below will read1
be always equal to read2
, provided property Flag
can be changed from other threads? Concern here is that Flag
may get inlined.
private bool Flag {get; set;}
public void MultithreadedMethod()
{
var read1 = Flag;
/* some more code */
var read2 = Flag;
}
UPD: Some other thread may change Flag
's value during /* some more code */
execution. In this case read1
should be different from read2
. Will it always be the case? Won't inlining turn the property into an non-volatile field that will cause read1
to be equal to read2
despite tha fact Flag
was changed between reads?