Reading a shared primitive variable in one thread may not yield the latest write to the variable from another thread. It is important to ensure that a read of a shared variable read sees the value of the most recent write to the variable. If this is not done, multiple threads may observe stale values of the shared variable and fail to act accordingly. Visibility of the latest value can be ensured by declaring the variable volatile
or correctly synchronizing the reads and writes to the variable.
...