1.JMM (Java Memory Model)
The Java Virtual Machine specification defines the Java memory model, which is used to mask the differences in memory access between different hardware and operating systems, so that Java programs can achieve consistent concurrency across all platforms. The JMM specifies how the Java virtual machine and computer memory work together, how one thread can see the values of shared variables modified by other threads, and how to access shared variables synchronously when necessary. Operations in the CPU, main memory data through the data bus read to the working memory work.Copy the code
2.MESI cache consistency protocol
A. Data is read to CPU and association to main memory through the main line. B. Volatile keyword By registering with the bus sniffing mechanism, data can be found to be modified, invalidating the cache data in the CPU.Copy the code
3. CPU assembly line
4. Principle of valitale keyword
Lock disallows instruction reordering and memory visibilityCopy the code
5. Data processing atomic operation
Read Load Use ASign Store Write Lock UNLOCKCopy the code
6. Double check lock singletons, can not volatile keyword?
No, new object is not done in one step, there is space allocation, initialization (constructor), point. Volatile prevents CPU instructions from being reordered.Copy the code