CAS atomic Operations--compare & Set, or Compare & Swap, now almost all CPU instructions support CAS atomic operations, X86 corresponding to CMPXCHG assembly instructions.
You should remember the concept of "atomic manipulation" inside the operating system, where an operation is atomic (atomic), and if the upper layer of this operation is not able to find its internal implementation and structure. An atomic operation can be a step or multiple steps, but its order cannot be disrupted, or it can be cut off only the execution part. With this atomic operation, we can achieve no lock.
Relative with lock ... Speed has improved
scene: Multiple variables synchronize atomic update, and In the case of fierce thread competition, CPU consumption is more serious.
Problem:ABA: A thread modifying the V-value hypothesis is a, first modified to B, then modified back to a. The current thread's CAS operation cannot tell if the current V value has changed
Lock-Free-cas atomic operation