-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
It seems to me that TestRaceRange should always be detected as a race. The code is:
func TestRaceRange(t *testing.T) {
const N = 2
var a [N]int
var x, y int
done := make(chan bool, N)
for i, v := range a {
go func(i int) {
// we don't want a write-vs-write race
// so there is no array b here
if i == 0 {
x = v
} else {
y = v
}
done <- true
}(i)
}
for i := 0; i < N; i++ {
<-done
}
}
The actual execution is
v = a[0]
go func() { x = v }()
v = a[1]
go func() { y = v }()
and the race is between the x = v and the v = a[1].
When Austin tweaked the goroutine scheduler behavior, the race detector stopped detecting this race. Adding a Gosched brought the detection of the race back, but it seems like it should be detected even without a Gosched.