On Sat, Apr 30, 2022 at 7:49 AM Zhaoxun Yan <yan.zhao...@gmail.com> wrote:
> Point-time race condition is undetectable by `go build race`. > When I run your code using `go run -race`, it reports a data race: > > ================== > WARNING: DATA RACE > Read at 0x0000005cb580 by main goroutine: > main.read() > /home/mero/tmp/x/x.go:15 +0xab > main.main() > /home/mero/tmp/x/x.go:26 +0x99 > Previous write at 0x0000005cb580 by goroutine 7: > main.increase() > /home/mero/tmp/x/x.go:11 +0x54 > main.main.func1() > /home/mero/tmp/x/x.go:21 +0x30 > main.main.func2() > /home/mero/tmp/x/x.go:24 +0x3e > Goroutine 7 (running) created at: > main.main() > /home/mero/tmp/x/x.go:19 +0x8e > ================== > 4 > Found 1 data race(s) > exit status 66 Go version is go version go1.18 linux/amd64 So, I don't really understand why you think the race detector can't detect that race. Thanks to Rust on emphasizing the single entrance to any variable, I > realized this possibility and have to add sync.Mutex to both functions. > > What is your opinion? > > Best Regards, > Zhaoxun > > -- > 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/5c6ae730-36a7-46ce-abb9-ea8d24da601bn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/5c6ae730-36a7-46ce-abb9-ea8d24da601bn%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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEBkjOmx0ZBCUEkETq7iM7_9vs0GQt3LjbA%2BqR6g0%2B%3DUQ%40mail.gmail.com.