You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this is allowed. There is no synchronization operation that would guarantee that the second goroutine would see the effects of the first one.
In the compiler, this happens because the memory state generated by the a=5 statement is never used, so it gets dead-code eliminated. That's why adding runtime.Gosched fixes it, because that call uses the aforementioned memory state.
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Finally
a: 5
should appear on the screenWhat did you see instead?
Always
a: 0
appears on the screen, anda = 5
instruction is disappeared. Is this the expected behavior?The text was updated successfully, but these errors were encountered: