You need to either use a mutex (or some other synchronization primitive) or atomic accesses <https://golang.org/pkg/sync/atomic/>.
On Thu, Mar 11, 2021 at 6:12 PM WX Lai <[email protected]> wrote: > Hi, > > 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. > > Thank you! > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/729079c1-6af7-4261-872e-bb65e76734bbn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/729079c1-6af7-4261-872e-bb65e76734bbn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfH9S6%2Bv%2BHQ2XRJ9pDxGpuReh8rrg7qfEJEF2w8DyO0NaQ%40mail.gmail.com.
