Hi Axel!

My project is in a folder.
So actually the best way to mimic the situation is to put this file in a 
folder. 
And then in that folder you run:
# go build -race
Nothing happens, at least in my go1.15
It did mention the race condition with `go run -race [filename]`
$ go run -race race.go
==================
WARNING: DATA RACE
Read at 0x0000006489c0 by main goroutine:
  main.read()
      /home/zxun/src/race.go:13 +0x6d
  main.main()
      /home/zxun/src/race.go:24 +0x5d

Previous write at 0x0000006489c0 by goroutine 7:
  main.increase()
      /home/zxun/src/race.go:9 +0x64
  main.main.func1()
      /home/zxun/src/race.go:19 +0x38

Goroutine 7 (running) created at:
  main.main()
      /home/zxun/src/race.go:17 +0x4f
==================
5
Found 1 data race(s)

Do you know the syntax to detect race condition for a whole folder of 
codes, instead of one file?
Thanks.
  Zhaoxun

在2022年4月30日星期六 UTC+8 14:05:45<axel.wa...@googlemail.com> 写道:

> On Sat, Apr 30, 2022 at 7:49 AM Zhaoxun Yan <yan.z...@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...@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/98c29132-d7d2-42f1-a219-e5bb558b67ban%40googlegroups.com.

Reply via email to