Commit 29415eb2 authored by Ian Lance Taylor's avatar Ian Lance Taylor

os: avoid crashing with a thundering herd in TestPipeThreads

Fixes #21559

Change-Id: I3393c4bee4c84fe0724a9c9aeb1a809b1a92eea6
Reviewed-on: https://go-review.googlesource.com/63650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJoe Tsai <joetsai@google.com>
parent c64e7938
......@@ -2205,22 +2205,24 @@ func TestPipeThreads(t *testing.T) {
defer debug.SetMaxThreads(debug.SetMaxThreads(threads / 2))
var wg sync.WaitGroup
wg.Add(threads)
c := make(chan bool, threads)
creading := make(chan bool, threads)
cdone := make(chan bool, threads)
for i := 0; i < threads; i++ {
go func(i int) {
defer wg.Done()
var b [1]byte
c <- true
creading <- true
if _, err := r[i].Read(b[:]); err != nil {
t.Error(err)
}
if err := r[i].Close(); err != nil {
t.Error(err)
}
cdone <- true
}(i)
}
for i := 0; i < threads; i++ {
<-c
<-creading
}
// If we are still alive, it means that the 100 goroutines did
......@@ -2233,14 +2235,7 @@ func TestPipeThreads(t *testing.T) {
if err := w[i].Close(); err != nil {
t.Error(err)
}
}
wg.Wait()
for i := 0; i < threads; i++ {
if err := r[i].Close(); err != nil {
t.Error(err)
}
<-cdone
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment