JUC Learning (6) "The underlying implementation principle of CAS"

JUC Learning (6) "The underlying implementation principle of CAS"


The full name of the concept CAS is Compare-And-Swap, which is the CPU concurrency primitive

Its function is to determine whether the value of a certain location in the memory is the expected value, and if it is, it is changed to a new value. This process is atomic

The CAS concurrency primitive embodied in the Java language is the various methods of the sun.misc.Unsafe class. Calling the CAS method in the UnSafe class, JVM will help us realize the CAS assembly instruction, which is a function completely dependent on the hardware, through which atomic operations are realized. Once again, because CAS is a system primitive, primitive It belongs to the category of operating system applications. It is composed of several instructions to complete a process of a certain function, and the execution of the primitive must be continuous, and it is not allowed to be interrupted during the execution, which means that CAS is a CPU Atomic instructions will not cause the so-called data inconsistency, which means that CAS is thread-safe.

Refer to https://www.cnblogs.com/youngdeng/p/12869037.html

Next
: "Source code and design of concurrentHashMap" of JUC learning (7)

Guess you like

Origin blog.csdn.net/nonage_bread/article/details/110933788