Eric, I read your comments, and one in particular struck me
In fact, I can understand that the use of concept volatility is level. But for practice, I can't think of code that has concurrency problems without using mutable
The obvious problem you may encounter is reordering the compiler, for example, the more famous upgrade mentioned by Simon Nickerson. But suppose there will be no reordering, this comment may be valid.
Another problem that is volatile to solve is with 64-bit variables (long, double). If you write long or double, it is considered as two separate 32-bit storages. What can happen with simultaneous recording is that a maximum of 32 of one stream is written to 32 bits of the register, and the other stream writes at least 32 bits. Then you can have a long one that is neither one nor the other.
Also, if you look at the JLS memory section, you will notice it as a laid-back memory model.
This means that the records may not become visible (may be in the storage buffer) for a while. This can lead to outdated readings. Now you can say that this is unlikely, and it is, but your program is incorrect and has the potential for failure.
If you have an int that you increase the lifetime of the application, and you know (or at least think) that int wont overflow, you do not update it to the end, but it is still possible. In the event of a memory visibility problem, if you think that this should not affect you, you should know that it still can and can lead to errors in your parallel application that are extremely difficult to identify. Correctness is the reason for using volatiles.
John Vint Apr 28 2018-11-11T00: 00Z
source share