github.com/ltltlt/go-source-code@v0.0.0-20190830023027-95be009773aa/cmd/go/testdata/src/testrace/race_test.go (about) 1 package testrace 2 3 import "testing" 4 5 func TestRace(t *testing.T) { 6 for i := 0; i < 10; i++ { 7 c := make(chan int) 8 x := 1 9 go func() { 10 x = 2 11 c <- 1 12 }() 13 x = 3 14 <-c 15 _ = x 16 } 17 } 18 19 func BenchmarkRace(b *testing.B) { 20 for i := 0; i < b.N; i++ { 21 c := make(chan int) 22 x := 1 23 go func() { 24 x = 2 25 c <- 1 26 }() 27 x = 3 28 <-c 29 _ = x 30 } 31 }