The race detector detects races, like smoke detectors detect smoke and water detectors detect water. Are you asking if the race detector is broken? If its judgement is just a guess? Not a guess. A scientific observation. Your code is not safe.
On Fri, Jul 5, 2019 at 7:53 AM Cholerae Hu <cholerae...@gmail.com> 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/825f9031-74b9-41b6-87af-dccfa7d98d04%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/825f9031-74b9-41b6-87af-dccfa7d98d04%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- *Michael T. jonesmichael.jo...@gmail.com <michael.jo...@gmail.com>* -- 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/CALoEmQzXrK2RnBpcpR7eQpAGPV4tNZZF0xNsuLjGMPSS2xHR9A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.