github.com/zxy12/golang_with_comment@v0.0.0-20190701084843-0e6b2aff5ef3/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 } 16 } 17 18 func BenchmarkRace(b *testing.B) { 19 for i := 0; i < b.N; i++ { 20 c := make(chan int) 21 x := 1 22 go func() { 23 x = 2 24 c <- 1 25 }() 26 x = 3 27 <-c 28 } 29 }