Thank you. Yes, the article introducing the go memory model gave precise conditions. However, if fg1 comes like: func fg1() { for x := uint64(0); x < math.MaxUint64; x++ { isRunning-- } } or func fg1() { if isRunning > 0 { isRunning = 0 } } Then the fg2() will return very quickly. 在2021年3月12日星期五 UTC+8 上午1:19:30<Jan Mercl> 写道:
> On Thu, Mar 11, 2021 at 6:12 PM WX Lai <0xbi...@gmail.com> wrote: > > > The code: https://repl.it/talk/share/The-assignment-disappeared/127774 > > > > The assignment of the global variable `isRunning` in function `fg1` does > not work at all. > > In fact, the assignment is deleted in the assembly (see the comment of > the link above). > > > > Why the compiler works like this? It disappeared after the process > `short circuit`, after all `isRunning` is used in `main` and `fg2`, making > `fg2` never return. > > The compiler is correct. The change to isRunning is not observable in > the goroutine that executes fg1() so there's no need to actually > update the variable. > -- 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/55a01c10-f593-42a1-82dd-40c2e1523d29n%40googlegroups.com.