Re: [go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread fgergo
Besides what others already suggested, you'll find the reason in the Go memory model specification: https://golang.org/ref/mem This part is relevant here: "If the effects of a goroutine must be observed by another goroutine, use a synchronization mechanism such as a lock or channel communication to

Re: [go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread White Pure
Thanks for your reply. I've tried before and it reported race. But I don't understand why this code has race, and what's the possible bug? Here's the output: $ go run -race main.go == WARNING: DATA RACE Write at 0x00c96000 by goroutine 7: main.main.func3() /Users/purewh

Re: [go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread Andrew Pillar
Have you tried building with the -race flag? go build - race This should help you figure out any data race conditions that may occur. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails fro

[go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread White Pure
Hi, I wrote some code like below these days, and my colleagues and me are not sure if the code has any concurrent problem. Can someone help to figure out if the code has any race problem? Thanks very much! Code: > package main > import ( "sync" "sync/atomic" ) > func main