package main import ( "sync/atomic" "sync" )
func main() { var n int32 var m sync.Mutex var wg sync.WaitGroup wg.Add(2) go func() { for { atomic.LoadInt32(&n) } wg.Done() }() go func() { for { m.Lock() n = 1 m.Unlock() } wg.Done() }() wg.Wait() } Does it safe to use atomic read an int and write an int non-atomically but in lock concurrently? Race detector will report it data 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/825f9031-74b9-41b6-87af-dccfa7d98d04%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.