sync.Cond: wait until a condition is announced
Answer: Cond is a condition variable: goroutines meet there to wait for an event or to announce one. Each Cond has a Locker L. The Locker L must be held when changing the condition and when calling Wait. Wait unlocks, suspends, and locks again. Signal wakes one goroutine. Broadcast wakes all.
Wait, Signal, and Broadcast
NewCond builds a Cond from a Locker.
Wait atomically unlocks c.L and suspends the calling goroutine.
After it resumes, Wait locks c.L before it returns.
In Go, Wait returns only after Signal or Broadcast wakes it.
c.L is not locked during the wait, so the caller typically cannot assume the condition is true when Wait returns.
The caller should Wait in a loop.
Broadcast wakes every goroutine waiting on c. Signal wakes one, if any is waiting.
The caller may hold c.L during Signal or Broadcast, but does not have to.
The associated locker, and a caution
Cond implements a condition variable, a rendezvous point for goroutines waiting for or announcing an event.
The associated Locker, often a Mutex or RWMutex, must be held when the condition changes and when Wait is called.
Do not copy a Cond after you first use it.
For simple cases, a channel is often a better tool than a Cond.
See also
Claims
- id: C1 claim: NewCond builds a Cond from a Locker. source: S1 evidence: "returns a new Cond with Locker"
- id: C2 claim: Wait unlocks the locker and suspends the caller. source: S1 evidence: "atomically unlocks c.L and suspends execution"
- id: C3 claim: Wait does not return unless Signal or Broadcast wakes it. source: S1 evidence: "cannot return unless awoken by"
- id: C4 claim: Broadcast wakes every waiting goroutine. source: S1 evidence: "wakes all goroutines waiting on c"
- id: C5 claim: A Cond is a rendezvous point for waiting or announcing an event. source: S2 evidence: "rendezvous point"
- id: C6 claim: The associated locker must be held when changing the condition and when calling Wait. source: S2 evidence: "must be held when changing the condition"
- id: C7 claim: A Cond must not be copied after first use. source: S2 evidence: "must not be copied after first use"
Sources
- [S1] sync package reference. Go. https://pkg.go.dev/sync . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] sync/cond.go source. Go. https://go.dev/src/sync/cond.go . License: BSD-3-Clause. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/cond.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/cond.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "sync.Cond: wait until a condition is announced." iinventedlight Library, iil:note:jr3g85ww, version of 2026-11-23. https://iinventedlight.com/library/notes/go-sync-cond/. License: CC-BY-4.0.
@misc{iil_note_jr3g85ww,
author = {{iinventedlight}},
title = {{sync.Cond: wait until a condition is announced}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-sync-cond/},
note = {Permanent ID iil:note:jr3g85ww. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-sync-cond.schema.json (schema; CC-BY-4.0)
- go-sync-cond.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-sync-cond.md.