The race detector is a heuristic. That it doesn't report a race does not mean there is none. Races are non-deterministic, so it's very possible that any particular run just didn't trigger one.
This slightly modified version of the same race triggers the race-detector reliably for me:
func f() {
wg := new(sync.WaitGroup)
defer wg.Wait()
a := 1
wg.Add(1)
go func() {
defer wg.Done()
fmt.Print(a)
a = 3
}()
fmt.Print(a)
}
func main() {
for i := 0; i < 1000; i++ {
f()
}
}
I just added a bit of synchronization to replace the time.Sleep and called the code 1000 times, to increase the likelihood of triggering the race.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3833aa84-9614-4815-ba1b-700b2de51df8n%40googlegroups.com.