]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix race in BenchmarkPingPongHog
authorRuss Cox <rsc@golang.org>
Mon, 27 Apr 2015 20:08:11 +0000 (16:08 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 27 Apr 2015 20:10:11 +0000 (20:10 +0000)
The master goroutine was returning before
the child goroutine had done its final i < b.N
(the one that fails and causes it to exit the loop)
and then the benchmark harness was updating
b.N, causing a read+write race on b.N.

Change-Id: I2504270a0de30544736f6c32161337a25b505c3e
Reviewed-on: https://go-review.googlesource.com/9368
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/proc_test.go

index fccf3970621bd1a6519236195d12e479415dee59..4c5712d32f6390c09e91c3356006c49fea787107 100644 (file)
@@ -366,18 +366,22 @@ func BenchmarkPingPongHog(b *testing.B) {
                        pong <- <-ping
                }
                close(stop)
+               done <- true
        }()
        go func() {
                for i := 0; i < b.N; i++ {
                        ping <- <-pong
                }
+               done <- true
        }()
        b.ResetTimer()
        ping <- true // Start ping-pong
        <-stop
        b.StopTimer()
        <-ping // Let last ponger exit
-       <-done // Make sure hog exits
+       <-done // Make sure goroutines exit
+       <-done
+       <-done
 }
 
 func stackGrowthRecursive(i int) {