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 →
Also covered in
What to know first
- atomicityAtomicity is the property that an operation or group of operations takes effect as an indivisible whole, without observable partial effects.
- deadlockA deadlock is a state in which concurrent activities cannot progress because each is waiting for a resource, event, or action that depends on another blocked activity.
- lockingLocking is a synchronization technique that controls concurrent access to a shared resource or protected operation.
Related concepts
- lock-freecontrasts with · Lock-free is a concurrency progress guarantee under which at least one 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 a protected operation, admitting only one thread at a time.
- 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 whole, without observable partial effects.
- compare-and-swapuses · Compare-and-swap is an atomic operation that replaces a value with a desired value only if the current value matches an expected value.
- lockingimplements · Locking is a synchronization technique that controls concurrent access to a shared resource or protected operation.
Questions about spinlock
What is 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.
Which Manning books explain spinlock?
C++ Concurrency in Action, Second Edition and Learn Concurrent Programming with Go.
What should I know before learning spinlock?
Manning books that teach spinlock usually introduce atomicity, deadlock and locking first.
What is the difference between spinlock and lock-free?
A spinlock is a mutual-exclusion synchronization primitive in which a waiting thread repeatedly checks or attempts to acquire the lock rather than blocking. Lock-free is a concurrency progress guarantee under which at least one operation completes within a finite number of steps despite contention, without relying on mutual-exclusion locks.
What is spinlock a kind of?
Spinlock is a kind of mutex. A mutex is a synchronization primitive that provides controlled exclusive access to shared data or a protected operation, admitting only one thread at a time.
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.

