]> Cypherpunks repositories - gostls13.git/commit
sync: fix spurious wakeup from WaitGroup.Wait
authorRui Ueyama <ruiu@google.com>
Thu, 10 Apr 2014 14:44:44 +0000 (18:44 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 10 Apr 2014 14:44:44 +0000 (18:44 +0400)
commite9347c781be66056bbc724f4d70d4b8b9bc0288c
tree39229004a7e137ea4209b815ced5423e3fbd4a8c
parent6278a9549288784563bfc9dc2f94cb0031e4ab2f
sync: fix spurious wakeup from WaitGroup.Wait

There is a race condition that causes spurious wakeup from Wait
in the following case:

 G1: decrement wg.counter, observe the counter is now 0
     (should unblock goroutines queued *at this moment*)
 G2: increment wg.counter
 G2: call Wait() to add itself to the wait queue
 G1: acquire wg.m, unblock all waiting goroutines

In the last step G2 is spuriously woken up by G1.
Fixes #7734.

LGTM=rsc, dvyukov
R=dvyukov, 0xjnml, rsc
CC=golang-codereviews
https://golang.org/cl/85580043
src/pkg/sync/waitgroup.go
src/pkg/sync/waitgroup_test.go