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 11,
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 hap
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
> 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 https://go.dev/ref/mem#badsyn
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
Hello, I have another question regarding the Go Memory Model.
(1) Can this program print "10", according to the Memory Model?
(2) If that is forbidden, which part of the Go Memory Model excludes such
behavior?
https://go.dev/play/p/Fn5I0fjSiKj
```go
package main
var x int = 0
func main() {
go