From 1fa0a8cec5f46bee1d652202934665a2ecdfc8d6 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Mon, 1 Jun 2015 13:25:03 +0900 Subject: [PATCH] runtime: fix data race in BenchmarkChanPopular Fixes #11014. Change-Id: I9a18dacd10564d3eaa1fea4d77f1a48e08e79f53 Reviewed-on: https://go-review.googlesource.com/10563 Reviewed-by: Brad Fitzpatrick --- src/runtime/chan_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime/chan_test.go b/src/runtime/chan_test.go index 9119371d5c..497e87f43d 100644 --- a/src/runtime/chan_test.go +++ b/src/runtime/chan_test.go @@ -898,6 +898,8 @@ func BenchmarkChanPopular(b *testing.B) { const n = 1000 c := make(chan bool) var a []chan bool + var wg sync.WaitGroup + wg.Add(n) for j := 0; j < n; j++ { d := make(chan bool) a = append(a, d) @@ -908,6 +910,7 @@ func BenchmarkChanPopular(b *testing.B) { case <-d: } } + wg.Done() }() } for i := 0; i < b.N; i++ { @@ -915,4 +918,5 @@ func BenchmarkChanPopular(b *testing.B) { d <- true } } + wg.Wait() }