]> Cypherpunks repositories - gostls13.git/commitdiff
sync: mention that WaitGroup.Add panics
authorRob Pike <r@golang.org>
Thu, 19 Jul 2012 18:55:03 +0000 (11:55 -0700)
committerRob Pike <r@golang.org>
Thu, 19 Jul 2012 18:55:03 +0000 (11:55 -0700)
Fixes #3839.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6428053

src/pkg/sync/waitgroup.go
src/pkg/sync/waitgroup_test.go

index 0165b1ffb2b4563f7abd6a00c4b3838d5d646bad..bc9e738e784ce31593574b00755a72bd9b58a6df 100644 (file)
@@ -32,10 +32,11 @@ type WaitGroup struct {
 
 // 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 goes negative, Add panics.
 func (wg *WaitGroup) Add(delta int) {
        v := atomic.AddInt32(&wg.counter, int32(delta))
        if v < 0 {
-               panic("sync: negative WaitGroup count")
+               panic("sync: negative WaitGroup counter")
        }
        if v > 0 || atomic.LoadInt32(&wg.waiters) == 0 {
                return
index 34430fc2158f2f1eb37ec857aa01b36370d13ae4..84c4cfc37a34a43bf2dc13d40263efbae5ff7789 100644 (file)
@@ -50,7 +50,7 @@ func TestWaitGroup(t *testing.T) {
 func TestWaitGroupMisuse(t *testing.T) {
        defer func() {
                err := recover()
-               if err != "sync: negative WaitGroup count" {
+               if err != "sync: negative WaitGroup counter" {
                        t.Fatalf("Unexpected panic: %#v", err)
                }
        }()