Reads of Reading a shared primitive variables variable in some one thread may not observe yield the latest writes write to the variables variable from other threadsanother thread. It is important to ensure that the accesses see the values a variable read sees the value of the most recent writeswrite to the variable. If this is not done, multiple threads may observe stale values of the shared variables variable and fail to act accordingly. Visibility of the latest values value can be ensured by declaring variables the variable volatile
or correctly synchronizing the codereads and writes to the variable.
The use of volatile
is recommended under a very restrictive set of conditions:
...