func TestWaitGroupMisuse2(t *testing.T) {
knownRacy(t)
- if testing.Short() {
- t.Skip("skipping flaky test in short mode; see issue 11443")
- }
- if runtime.NumCPU() <= 2 {
- t.Skip("NumCPU<=2, skipping: this test requires parallelism")
+ if runtime.NumCPU() <= 4 {
+ t.Skip("NumCPU<=4, skipping: this test requires parallelism")
}
defer func() {
err := recover()
}()
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4))
done := make(chan interface{}, 2)
- // The detection is opportunistically, so we want it to panic
+ // The detection is opportunistic, so we want it to panic
// at least in one run out of a million.
for i := 0; i < 1e6; i++ {
var wg WaitGroup
+ var here uint32
wg.Add(1)
go func() {
defer func() {
done <- recover()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Wait()
}()
go func() {
defer func() {
done <- recover()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Add(1) // This is the bad guy.
wg.Done()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Done()
for j := 0; j < 2; j++ {
if err := <-done; err != nil {