RE: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-14 Thread John Souvestre
ang-nuts Subject: Re: [go-nuts] does Go memory model guarantee this program always prints 1? [Reply-To set; I don't need two copies of replies.] * T L [170710 12:31]: > so this is guaranteed by Go memory model? > > package main > > import "fmt" > impor

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
* T L [170710 12:35]: > so this is guaranteed by Go memory model? > > package main > > import "fmt" > import "sync/atomic" > import "unsafe" > > func main() { > var x, y int32 > > var p = unsafe.Pointer(&x) > > atomic.AddInt32(&x, 1) > atomic.AddInt32(&y, 1) > >

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
* T L [170710 12:32]: > so this is guaranteed by go memory model? > > package main > > import "fmt" > import "sync/atomic" > > func main() { > var x, y int32 > > atomic.AddInt32(&x, 1) > atomic.AddInt32(&y, 1) > > if atomic.LoadInt32(&y) == 1 { > fmt.Println("x

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
[Reply-To set; I don't need two copies of replies.] * T L [170710 12:31]: > so this is guaranteed by Go memory model? > > package main > > import "fmt" > import "sync/atomic" > > func main() { > var x, y int32 > go func() { > atomic.AddInt32(&x, 1) > atomic.AddInt32(&y,

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread T L
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote: > > On Mon, Jul 10, 2017 at 2:24 PM T L > > wrote: > > > Aha, what I wanted to express is the execution orders of the two lines > may be randomized. > > > > atomic.AddInt32(&x, 1) > > atomic.AddInt32(&y, 1) > > No, assuming those

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread T L
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote: > > On Mon, Jul 10, 2017 at 2:24 PM T L > > wrote: > > > Aha, what I wanted to express is the execution orders of the two lines > may be randomized. > > > > atomic.AddInt32(&x, 1) > > atomic.AddInt32(&y, 1) > > No, assuming those

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread T L
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote: > > On Mon, Jul 10, 2017 at 2:24 PM T L > > wrote: > > > Aha, what I wanted to express is the execution orders of the two lines > may be randomized. > > > > atomic.AddInt32(&x, 1) > > atomic.AddInt32(&y, 1) > > No, assuming those

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Jan Mercl
On Mon, Jul 10, 2017 at 2:24 PM T L wrote: > Aha, what I wanted to express is the execution orders of the two lines may be randomized. > > atomic.AddInt32(&x, 1) > atomic.AddInt32(&y, 1) No, assuming those two lines are as written, ie. part of single function and thus executed in a single/the sa

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread T L
On Sunday, July 9, 2017 at 5:10:20 PM UTC+8, Jan Mercl wrote: > > On Sun, Jul 9, 2017 at 10:56 AM T L > > wrote: > > > But I remember that the "happens-before relationship" is never written > down in any official Go documentation. > > https://golang.org/ref/mem#tmp_2 > > > -- > > -j > Aha, wh

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread Marvin Renich
* T L [170709 04:56]: > On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote: > > Yes, the go routine establishes a happens-before relationship such that > > x is incremented before y, and the atomic Add of y and Load of y ensure > > that the Load either happens before or after, but

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread Jan Mercl
On Sun, Jul 9, 2017 at 10:56 AM T L wrote: > But I remember that the "happens-before relationship" is never written down in any official Go documentation. https://golang.org/ref/mem#tmp_2 -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" grou

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread T L
On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote: > > * T L > [170707 01:32]: > > Then how about this? > > > > package main > > > > import "fmt" > > import "sync/atomic" > > > > func main() { > > var x, y int32 > > go func() { > > atomic.AddInt32(&x, 1)

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-07 Thread Marvin Renich
* T L [170707 01:32]: > 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.Pr

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-07 Thread peterGo
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" >>

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-06 Thread andrey mirtchovski
> Then how about this? No. -- 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.googl

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-06 Thread T L
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

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-06 Thread Lars Seipel
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 >

[go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-06 Thread T L
package main import "fmt" import "sync/atomic" func main() { var x int32 atomic.AddInt32(&x, 1) fmt.Println(atomic.LoadInt32(&x)) } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving e