You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does 'go version' print?
go version devel +519230b4d06a Sun Apr 06 10:30:02 2014 -0400 + linux/amd64
What steps reproduce the problem?
The following program, which uses a WaitGroup to wait for two goroutines to complete,
should never exit.
package main
import (
"fmt"
"runtime"
"sync"
"sync/atomic"
)
func main() {
for i := int64(0); ; i++ {
wg := &sync.WaitGroup{}
wg.Add(1)
counter := int32(0)
// spawn goroutine 1
go func() {
atomic.AddInt32(&counter, 1)
wg.Done()
}()
runtime.Gosched()
wg.Add(1)
// spawn goroutine 2
go func() {
atomic.AddInt32(&counter, 1)
wg.Done()
}()
// Wait for goroutine 1 and 2
wg.Wait()
if atomic.LoadInt32(&counter) != 2 {
fmt.Println(i, "Spurious wakeup from Wait()")
return
}
}
}
What happened?
It exits because of a bug in WaitGroup. (It may take a few minutes to fail.)
$ GOMAXPROCS=2 go run test.go
26994961 Spurious wakeup from Wait()
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: