1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:20:22 -07:00

sync: add caution about where to call (*WaitGroup).Add

Fixes #4762.

R=daniel.morsing, adg
CC=golang-dev
https://golang.org/cl/7308045
This commit is contained in:
Russ Cox 2013-02-11 08:05:46 -05:00
parent 71c941b6f6
commit 02e05817ad

View File

@ -34,8 +34,13 @@ type WaitGroup struct {
// G3: Wait() // G1 still hasn't run, G3 finds sema == 1, unblocked! Bug.
// Add adds delta, which may be negative, to the WaitGroup counter.
// If the counter becomes zero, all goroutines blocked on Wait() are released.
// If the counter becomes zero, all goroutines blocked on Wait are released.
// If the counter goes negative, Add panics.
//
// Note that calls with positive delta must happen before the call to Wait,
// or else Wait may wait for too small a group. Typically this means the calls
// to Add should execute before the statement creating the goroutine or
// other event to be waited for. See the WaitGroup example.
func (wg *WaitGroup) Add(delta int) {
if raceenabled {
raceReleaseMerge(unsafe.Pointer(wg))