Member-only story
Go High-Performance Programming EP10: Two Useful Golang Lock-Free Programming Tips
Understanding the Essence of Lock-Free Programming
Inlock-free programming, the absence of locks is more superficial. Programmers aim to organize data and processing to eliminate data races. Traditional concurrent programming often uses critical sections, exclusive locks, or read-write locks to protect data from incorrect reads or writes during processing. In contrast, lock-free programming resolves these issues by eliminating shared data or concurrent operations on the same data.
Two of the most common techniques in lock-free programming include:
- Structure Copy
- Bumper Loop
Other methods are derivatives of the same principles.
The “other methods” mentioned here refer to algorithm designs that do not rely on locker or CAS. This article discusses designing data structures and algorithms that avoid locker and CAS.
Some lock-free solutions, such as RingBuffer libraries, forcefully eliminate race conditions on shared data. However, they depend highly on the specific data structure and CPU design. These are constrained approaches with limited abstraction and generality. For instance, a well-designed RingBuffer should be more…

