Re: [go-nuts] Does this code safe?

2019-07-05 Thread Steven Hartland
Use the same method for both Load and Set, also your example will never complete as your for loops will run forever. On 05/07/2019 15:53, 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() {

[go-nuts] Does this code safe?

2019-07-05 Thread Cholerae Hu
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() } 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