The definition of volatile in the third edition of the Java Language specification is as follows:
The Java programming language allows threads to access shared variables, and in order to ensure that shared variables can be updated accurately and consistently, the thread should ensure that an exclusive lock
Get this variable separately.
Volatile is sometimes more convenient than a lock, such as a field that is declared as a Volatile,java thread memory model to ensure that all threads see this variable
The values are consistent.
How does volatile ensure visibility? When you need to see the Java code translated into assembly code, the process of implementation can refer to the art of Java concurrent programming
Chapter II, or other information. (Mostly I'm not familiar with the assembly)
It also involves the principle of CPU and memory and its caching.
It technology and industry exchange Group 417691667
Java concurrency Programming underlying implementation principle-volatile