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 0x00c000096000 by goroutine 7: main.main.func3() /Users/purewhite/go/src/xxx/main.go:26 +0x46
Previous read at 0x00c000096000 by goroutine 5: sync/atomic.LoadInt32() /usr/local/Cellar/go/1.12.6/libexec/src/runtime/race_amd64.s:206 +0xb main.main.func1() /Users/purewhite/go/src/xxx/main.go:13 +0x38 Goroutine 7 (running) created at: main.main() /Users/purewhite/go/src/xxx/main.go:23 +0x115 Goroutine 5 (running) created at: main.main() /Users/purewhite/go/src/xxx/main.go:11 +0xbd ================== Found 1 data race(s) exit status 66 在 2019年7月5日星期五 UTC+8下午6:48:11,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 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/9c57fc61-141b-40b5-947a-5d7a3ad3547e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.