]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix data race in BenchmarkChanPopular
authorMikio Hara <mikioh.mikioh@gmail.com>
Mon, 1 Jun 2015 04:25:03 +0000 (13:25 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Tue, 2 Jun 2015 11:16:01 +0000 (11:16 +0000)
Fixes #11014.

Change-Id: I9a18dacd10564d3eaa1fea4d77f1a48e08e79f53
Reviewed-on: https://go-review.googlesource.com/10563
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/chan_test.go

index 9119371d5c6b782bf80f54bc71947da5217736c1..497e87f43d95f4618fea9d43d649b62f49ec6626 100644 (file)
@@ -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()
 }