Spinlock
A spinlock is a mutual-exclusion synchronization primitive in which a waiting thread repeatedly checks or attempts to acquire the lock rather than blocking.
C++ Concurrency in Action, Second Edition
A mutex implementation in which a waiting thread repeatedly attempts to acquire the lock rather than blocking.
- How it is used
- Uses repeated atomic-flag attempts to implement mutual exclusion without a blocking call.
- How deep it goes
- Works through lock and unlock operations and their acquire-release ordering; warns about contention rather than developing a contention-handling strategy.
- Examples
- Shows a std::atomic_flag mutex and a barrier that yields while waiting for its generation to change.
- What you can do after
- Build it from scratch with std::atomic_flag and evaluate when busy-waiting or lock dependence makes it unsuitable.
Read how C++ Concurrency in Action, Second Edition explains spinlock →
Learn Concurrent Programming with Go
A spin lock is a mutual-exclusion lock whose unsuccessful acquisition repeatedly retries while the execution remains active instead of blocking.
- How it is used
- Protects grouped shared-state updates, such as multi-flight reservations, when single-variable atomic updates are insufficient.
- How deep it goes
- Works through a complete Go Locker implementation using an atomic integer, CompareAndSwap loop, scheduler yield, and atomic unlock.
- Examples
- Uses a multi-flight booking race and a Go SpinLock implementation with a 0/1 state flag.
- What you can do after
- Build it from scratch as a Go sync.Locker and extend it with TryLock or a spinning semaphore.
Read how Learn Concurrent Programming with Go explains spinlock →
Related concepts
- lockless techniquecontrasts with · Lock-free is a concurrency progress property that guarantees some operation completes within a finite number of steps despite contention, without relying on mutual-exclusion locks.
- mutexkind of · A mutex is a synchronization primitive that provides controlled exclusive access to shared data or another resource.
- atomic_flagimplemented by · An atomic flag is a standard atomic type representing a flag and providing indivisible operations to set or clear it for synchronization.
- atomicityimplemented by · Atomicity is the property that an operation or group of operations takes effect as an indivisible, all-or-nothing unit, without observable partial effects.
- lockingimplements · Locking is a synchronization technique that restricts concurrent access to shared resources or protected operations.
- compare-and-exchange operationuses · A compare-and-exchange operation atomically replaces a value with a desired value only if the current value matches an expected value.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

