From: Michael Pratt Date: Fri, 9 Feb 2024 19:16:11 +0000 (-0500) Subject: internal/trace: fix race condition in gc-stress X-Git-Tag: go1.23rc1~1257 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=09c62a86a96e51d535336de1c7b7e10cd3acd849;p=gostls13.git internal/trace: fix race condition in gc-stress Multiple goroutines all writing to the same sink triggers the race detector, rightfully so. Change-Id: Ia64836d0d88c0f587a6cb96ed747f656a3c1804a Reviewed-on: https://go-review.googlesource.com/c/go/+/562997 LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Pratt Reviewed-by: Michael Knyszek --- diff --git a/src/internal/trace/v2/testdata/testprog/gc-stress.go b/src/internal/trace/v2/testdata/testprog/gc-stress.go index 70d3a246c3..017f7f07bf 100644 --- a/src/internal/trace/v2/testdata/testprog/gc-stress.go +++ b/src/internal/trace/v2/testdata/testprog/gc-stress.go @@ -39,7 +39,7 @@ func makeTree(depth int) *node { var trees [16]*node var ballast *[16]*[8192]*node -var sink []byte +var sink [][]byte func main() { for i := range trees { @@ -54,10 +54,15 @@ func main() { } } } - for i := 0; i < runtime.GOMAXPROCS(-1); i++ { + + procs := runtime.GOMAXPROCS(-1) + sink = make([][]byte, procs) + + for i := 0; i < procs; i++ { + i := i go func() { for { - sink = make([]byte, rand.Intn(32<<10)) + sink[i] = make([]byte, rand.Intn(32<<10)) } }() }