liveBook · Manning

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.

How 2 Manning books explain it

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

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.