]> Cypherpunks repositories - gostls13.git/commitdiff
sync: add caution about where to call (*WaitGroup).Add
authorRuss Cox <rsc@golang.org>
Mon, 11 Feb 2013 13:05:46 +0000 (08:05 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 11 Feb 2013 13:05:46 +0000 (08:05 -0500)
Fixes #4762.

R=daniel.morsing, adg
CC=golang-dev
https://golang.org/cl/7308045

src/pkg/sync/waitgroup.go

index 9b0ffec58b34b6af2bc8c198606e9c6234a0faa6..1277f1c6dec63693b9422afd580a64242d4950d7 100644 (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))