In the code below will read1
be always equal to read2
, provided property Flag
can be changed from other threads? Concern here is that
According to the documentation
The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread. ... Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.