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<Jan Mercl> 写道:

> On Wed, May 12, 2021 at 7:55 PM Ge <everg...@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/d388637b-91ce-4740-b58a-7061d84daea8n%40googlegroups.com.

Reply via email to