On Saturday, October 21, 2017 at 6:38:29 PM UTC-4, Dave Cheney wrote:
>
> no to your first example, yes to the second.
>

Thanks.

Yes, the second is really mentioned in the Lock section in 
https://golang.org/ref/mem

BTW, I can't find the context for the *n* and *m* *(n < m) *in this section.
What do them mean?
 

>
> On Sunday, 22 October 2017 08:01:08 UTC+11, T L wrote:
>>
>> 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.

Reply via email to