---
source: https://iinventedlight.com/library/notes/go-sync-waitgroup.md
title: "sync.WaitGroup: wait for a group of goroutines to finish"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/waitgroup.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-sync-waitgroup"
tags: [go, sync, waitgroup, concurrency, goroutines]
client: Librarian
sources:
  - id: S1
    title: "sync package reference"
    publisher: Go
    url: https://pkg.go.dev/sync
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "sync/waitgroup.go source"
    publisher: Go
    url: https://go.dev/src/sync/waitgroup.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# sync.WaitGroup: wait for a group of goroutines to finish
**Answer:** A WaitGroup is a counting semaphore used to wait for goroutines or tasks to finish. Start the work, then call Wait(). A WaitGroup must not be copied after first use.

## Waiting for a group of tasks

A WaitGroup is a counting semaphore used to wait for goroutines or tasks to finish.

A main goroutine can start tasks, each in a new goroutine, by calling WaitGroup.Go, then wait for all tasks to complete by calling WaitGroup.Wait.

## The older Add and Done pattern

Add and Done can track tasks when you do not use Go to start new goroutines.

The same work can use explicitly created goroutines along with Add and Done.

This pattern is common in code that predates WaitGroup.Go.

## Copying rules in the source

Both the package docs and the waitgroup.go comments say a WaitGroup must not be copied after first use.

This pattern is common in code that predates WaitGroup.Go.

## See also

- [go-goroutines](https://iinventedlight.com/library/notes/go-goroutines/)
- [go-once](https://iinventedlight.com/library/notes/go-once/)
- [go-errgroup](https://iinventedlight.com/library/notes/go-errgroup/)

## Claims

- id: C1
  claim: A WaitGroup is a counting semaphore for waiting on a group of tasks.
  source: S1
  evidence: "A WaitGroup is a counting semaphore typically used to wait"

- id: C2
  claim: WaitGroup.Go starts a task; Wait waits until the group is done.
  source: S1
  evidence: "by calling WaitGroup.Go and then wait for all tasks to complete"

- id: C3
  claim: Add and Done can track work you start yourself.
  source: S1
  evidence: "using WaitGroup.Add and WaitGroup.Done"

- id: C4
  claim: A WaitGroup must not be copied after first use.
  source: S2
  evidence: "A WaitGroup must not be copied after first use"

- id: C5
  claim: The Add and Done pattern predates WaitGroup.Go.
  source: S2
  evidence: "This pattern is common in code that predates"

## Sources

- [S1] sync package reference. Go. https://pkg.go.dev/sync . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] sync/waitgroup.go source. Go. https://go.dev/src/sync/waitgroup.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/waitgroup.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
