package main import "fmt" import "sync" import "sync/atomic"
func main() { var a, b int32 = 0, 0 go func() { a = 1 atomic.AddInt32(&b, 1) }() for { if n := atomic.LoadInt32(&b); n == 1 { fmt.Println(a) // always print 1? break } } //====================== var x, y int32 = 0, 0 var m sync.Mutex go func() { x = 1 m.Lock() y++ m.Unlock() }() for { m.Lock() n := y m.Unlock() if n == 1 { fmt.Println(x) // always print 1? break } } } -- 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. For more options, visit https://groups.google.com/d/optout.