← All notes

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

Sources

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

Permanent ID: iil:note:jr3g85ww

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.},
}

Markdown

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.

All artifact files (JSON index)

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.