T L,

No: https://github.com/golang/go/issues/19182

Peter

On Friday, July 7, 2017 at 5:31:33 AM UTC, T L wrote:
>
>
>
> On Friday, July 7, 2017 at 3:26:24 AM UTC+8, Lars Seipel wrote:
>>
>> On Thu, Jul 06, 2017 at 12:19:05PM -0700, T L wrote: 
>> > 
>> > package main 
>> > 
>> > import "fmt" 
>> > import "sync/atomic" 
>> > 
>> > func main() { 
>> >     var x int32 
>> >     atomic.AddInt32(&x, 1) 
>> >     fmt.Println(atomic.LoadInt32(&x)) 
>> > } 
>>
>> Sure. 
>>
>> > Within a single goroutine, the happens-before order is the order 
>> > expressed by the program. 
>> - https://golang.org/ref/mem
>
>
> Thanks.
>
> Then how about this?
>
> package main
>
> import "fmt"
> import "sync/atomic"
>
> func main() {
>     var x, y int32
>     go func() {
>         atomic.AddInt32(&x, 1)
>         atomic.AddInt32(&y, 1)
>     }()
>     
>     if atomic.LoadInt32(&y) == 1 {
>         fmt.Println("x =", atomic.LoadInt32(&x)) // always 1 if it is 
> printed?
>     }
>     
>     if atomic.LoadInt32(&x) == 0 {
>         fmt.Println("y =", atomic.LoadInt32(&y)) // always 0 if it is 
> printed?
>     }
> }
>  
>

-- 
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