In theory, the non-atomic store could tear with respect to the atomic load.
On Friday, 5 July 2019 10:53:05 UTC-4, Cholerae Hu wrote: > > 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/c8a2c785-e54f-4bf9-abe0-c1136225f521%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.