Sitemap
The Ordinary Programmer

The Ordinary Programmer is for coders who embrace simplicity and practicality. We share real-world tips, project stories, and tech insights for developers at every level. You don’t need to be a superstar — just a programmer who loves to learn and build helpful software.

Member-only story

Go High-Performance Programming EP10: Two Useful Golang Lock-Free Programming Tips

4 min readOct 19, 2024

--

Press enter or click to view image in full size
Photo by James Harrison on Unsplash

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:

  1. Structure Copy
  2. 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…

--

--

The Ordinary Programmer
The Ordinary Programmer

Published in The Ordinary Programmer

The Ordinary Programmer is for coders who embrace simplicity and practicality. We share real-world tips, project stories, and tech insights for developers at every level. You don’t need to be a superstar — just a programmer who loves to learn and build helpful software.

huizhou92
huizhou92

Written by huizhou92

Golang backend engineer. Specializes in cloud, data, and security. Lifelong learner. Efficiency enthusiast.