WaitGroup
WaitGroup is a synchronization type that counts concurrent operations and allows execution to wait until the counter reaches zero.
Learn Concurrent Programming with Go
A waitgroup is a synchronization object that allows execution to wait until a counted set of concurrent operations has completed.
- How it is used
- Coordinates a main or waiting goroutine with a group of concurrent tasks that must finish before execution proceeds.
- How deep it goes
- Explains Add, Done, and Wait, then builds fixed and dynamically sized implementations from semaphores and condition variables.
- Examples
- Uses four delayed workers, concurrent letter-frequency counting, and recursive filename search.
- What you can do after
- Build it from scratch with semaphore or condition-variable primitives, and apply sync.WaitGroup to await concurrent work.
Read how Learn Concurrent Programming with Go explains WaitGroup →
Learn Go with Pocket-Sized Projects
sync.WaitGroup is a Go synchronization type that allows one goroutine to wait for a collection of goroutines to finish.
- How it is used
- Coordinates goroutines so a controlling goroutine does not finish before registered concurrent work completes.
- How deep it goes
- Explains Add, Done, and Wait with runnable examples, pointer semantics, loop registration, and coordinator placement.
- Examples
- Uses cooking tasks, a ten-writer cache test, and a concurrent maze solver listener.
- What you can do after
- Build it from scratch to coordinate goroutines, wait for completion, and structure concurrent tests.
Read how Learn Go with Pocket-Sized Projects explains WaitGroup →
Go in Action, Second Edition
WaitGroup is a Go synchronization type that counts active operations and blocks until its counter reaches zero.
- How it is used
- Coordinates concurrent feed fetching so callers wait for all goroutines before proceeding.
- How deep it goes
- Works through counter-based waiting, Go, and Add/Done/Wait patterns, but leaves error collection to other mechanisms.
- Examples
- Uses concurrent RSS feed fetching and an HTTP handler that aggregates articles and errors.
- What you can do after
- Apply it via sync.WaitGroup to await goroutines and close a results channel after its producers finish.
Go in Practice, Second Edition
A wait group is a synchronization primitive that lets a program wait for a collection of concurrent tasks to finish.
- How it is used
- Coordinates goroutines performing independent jobs before the coordinating process safely continues.
- How deep it goes
- Defines count-based synchronization and demonstrates Add, Done, and Wait in a parallel file-compression program.
- Examples
- Uses command-line file compression with compress/gzip and produces .gz files before printing a summary.
- What you can do after
- Build it from scratch by coordinating multiple goroutines and waiting for their completion.
Read how Go in Practice, Second Edition explains WaitGroup →
100 Go Mistakes and How to Avoid Them
sync.WaitGroup is a Go synchronization type that allows code to wait for a specified number of concurrent operations to complete.
- How it is used
- Coordinates completion of a known group of goroutines before subsequent code proceeds.
- How deep it goes
- Explains the zero value, counter operations, blocking Wait, panic condition, and Add-ordering failure, but not implementation internals.
- Examples
- Demonstrates three goroutines updating an atomic counter, premature Wait completion, and corrected Add-before-go patterns.
- What you can do after
- Diagnose/debug with it by placing Add before goroutine creation and checking race-detector reports for premature completion.
Read how 100 Go Mistakes and How to Avoid Them explains WaitGroup →
Related concepts
- WaitGroup Done methodhas part · WaitGroup.Done is a method that decrements a wait group's counter by one to mark a tracked operation as finished.
- WaitGroup.Waithas part · WaitGroup.Wait is a method that blocks until the associated wait group's counter reaches zero.
- sync packagepart of · The sync package is Go’s standard-library package providing synchronization primitives for coordinating concurrent execution and protecting shared data.
- goroutineuses · A goroutine is a lightweight function execution unit managed by the Go runtime that runs concurrently with other program activity.
- condition variableimplemented by · A condition variable is a synchronization object that allows threads to wait for a shared-state condition and be notified when it may have changed.
- add methodhas part · The Add method of sync.WaitGroup changes the number of concurrent operations that a WaitGroup waits to complete.
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.




