July 2018
Intermediate to advanced
266 pages
7h 11m
English
There is a common misconception about what volatile variables guarantee. So to understand when it's useful, we need to go back to considering the thread-safe counter from previous examples. During previous explanations, I indicated that the atomicity violations in the example happen because two threads read the value of a variable really close in time, which in turn causes some of the changes to be lost. But there's a little more to it; there can be two reasons why both threads read the same value:
Read now
Unlock full access