I can convince myself that data races need not be a race condition. Consider this simple program:
var i int
doneCh := make(chan struct{})
go func() { i = 1; doneCh <- struct{}{} }() // a
go func() { i = 1; doneCh <- struct{}{} }() // b
<-doneCh
<-doneCh
At the end of the program, i is always equal to 1 no matter which order a or b wrote to i. But it's a race because you are assigning to a shared variable without synchronization. A small modification to the program creates a race condition:
var i int
doneCh := make(chan struct{})
go func() { i = 1; doneCh <- struct{}{} }() // a
go func() { i = 2; doneCh <- struct{}{} }() // b
<-doneCh
<-doneCh
Is i 1 or 2? It depends.
It is correct for the race checker to complain about the first program, because after a bit of hacking the first program can very easily change into the second program.
I wasn't sure. After a bit of research, this seems to be a debate [1]. Using the common definitions, it's possible to have a data race that doesn't cause a race condition. [2] It's also possible to have a race condition without a data race.
It is correct for the race checker to complain about the first program, because after a bit of hacking the first program can very easily change into the second program.
(And I tried it, and it does complain.)