liveBook · Manning

Sync.Cond

sync.Cond is a Go standard-library condition-variable type that coordinates waiting and signaling among goroutines using a sync.Locker.

How 2 Manning books explain it

100 Go Mistakes and How to Avoid Them

sync.Cond is a Go synchronization type that coordinates goroutines waiting for a condition associated with a locker.

How it is used
Coordinates goroutines waiting for different conditions on shared state, especially when one update must notify multiple listeners.
How deep it goes
Explains busy-loop and channel alternatives before showing a complete sync.Cond implementation with locking, waiting, and broadcasting.
Examples
Uses donation balances, $10 and $15 goals, busy polling, shared-channel delivery, and Broadcast-based waiting.
What you can do after
Apply it via sync.Cond to notify multiple goroutines whenever shared state changes.

Read how 100 Go Mistakes and How to Avoid Them explains sync.Cond →

Learn Concurrent Programming with Go

The Go standard-library condition-variable type that coordinates waiting and signaling through a sync.Locker.

How it is used
Coordinates goroutines waiting for shared state to satisfy a condition, such as having enough money to spend.
How deep it goes
Explains the API and guarded wait-signal pattern, including atomic unlock-and-suspend behavior, but avoids implementation internals.
Examples
Uses Stingy and Spendy goroutines to coordinate deposits and spending through a shared bank balance.
What you can do after
Build it from scratch using sync.NewCond, Locker methods, Wait, Signal, and a mutex-protected condition loop.

Read how Learn Concurrent Programming with Go explains sync.Cond →

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.