Re: [go-nuts] Go Memory Model question

2022-12-03 Thread robert engels
happens-before in this case would only guarantee 0, not 1. e.g. change the initializer to x = 3, then 3 must be guaranteed to be seen rather than the default value of 0 > On Dec 2, 2022, at 8:12 AM, burak serdar wrote: > > The way I read the memory model, this program can print 01, 00, and

Re: [go-nuts] Go Memory Model question

2022-12-03 Thread Quân Anh Mai
A. From the theoretical point of view given this program: Initial: x = 0 Thread 1: x = 1 Thread 2: x1 = x x2 = x If x1 = 1, we have the following happen-before relationship: - x = 0 happens before x = 1 - x = 0 happens before x1 = x - x1 = x happens before x2 = x Note that there is no x = 1

Re: [go-nuts] Go Memory Model question

2022-12-02 Thread burak serdar
The way I read the memory model, this program can print 01, 00, and 11, but not 10. This is because goroutine creation creates a synchronized before relationship between x=1 and x=0, so even though there is a race, x=0 happens before x=1. On Fri, Dec 2, 2022 at 6:56 AM のびしー wrote: > > I believe

Re: [go-nuts] Go Memory Model question

2022-12-02 Thread のびしー
> I believe your example is basically equivalent to the ones in https://go.dev/ref/mem#badsync which also contains an explanation of how the memory model implies this @Wagner Thanks for your opinion, I think so too. I was not confident that my example is equivalent to

Re: [go-nuts] Go Memory Model question

2022-12-02 Thread 'Axel Wagner' via golang-nuts
I believe your example is basically equivalent to the ones in https://go.dev/ref/mem#badsync which also contains an explanation of how the memory model implies this (or rather, how it does not imply the opposite). On Fri, Dec 2, 2022, 13:11 のびしー wrote: > Hello, I have another question regarding