On Wed, May 12, 2021 at 7:55 PM Ge <evergon...@gmail.com> 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
> }

There's no synchronization in this code, so other goroutines  reading
A or B w/o said synchronization may observe any values. Stalled,
changing in wrong order, random..., you name it.

But if has nothing to do with defer. The particular code is equal to

var A, B int
func try() {
     A = 3
     B = 5
}

with the set of problems as the version using defer.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-VMhaQgVTd%3D45Quh94GjFh9xeKzxn-K3BnGd5GwG9ygdg%40mail.gmail.com.

Reply via email to