Thanks Jan and Axel, I may need to figure out go memory model and hardware
memory model.
在2021年5月13日星期四 UTC+8 上午2:15:43 写道:
> On Wed, May 12, 2021 at 7:55 PM Ge wrote:
>
> > Do you mean in following case if anthoer goroutine is observing A and B,
> > there is no possbility that A is 0 and B is
On Wed, May 12, 2021 at 7:55 PM Ge wrote:
> Do you mean in following case if anthoer goroutine is observing A and B,
> there is no possbility that A is 0 and B is 5? (assuming no other
> synchronization here)
>
> ```
> var A, B int
> func try() {
> defer func() { B = 5 }
> A = 3
> }
The
If we assume no other synchronization here, you have concurrent
modification of variables, which is undefined behavior.
But to answer your original questions: Yes, the behavior of `defer` is
included in the clause "the order expressed by the program" - "the order
specified by the program" doesn't
Thank you Jan, sorry for my bad english.
Do you mean in following case if anthoer goroutine is observing A and B,
there is no possbility that A is 0 and B is 5? (assuming no other
synchronization here)
```
var A, B int
func try() {
defer func() { B = 5 }
A = 3
}
Ge
在2021年5月12日星期三 UTC+8
On Wed, May 12, 2021 at 4:38 PM Ge wrote:
>
> According to https://golang.org/ref/spec#Defer_statements there is such an
> expression:
> `A "defer" statement invokes a function whose execution is deferred to the
> moment the surrounding function returns`
>
> Does `defer` ensure happens-before
According to https://golang.org/ref/spec#Defer_statements there is such an
expression:
* `A "defer" statement invokes a function whose execution is deferred to
the moment the surrounding function returns`*
Does `defer` ensure happens-before behaviour with non-defer code?
I have read https://go