...
Declaring flag
volatile solves the problem of reading values being cached, which causes stale data but to be read. However, volatile flag
still does not provide atomicity guarantees needed for synchronization primitives to work correctly. The volatile
keyword does not promise to provide the guarantees needed for synchronization primitives.
...