Hi Dave,
1. the report:
> go version
go version go1.10 darwin/amd64
> go test -v -race -count=5 .
=== RUN TestSyncAPI
==================
WARNING: DATA RACE
Read at 0x00c4200ca080 by goroutine 8:
_/Users/yanqing11/test/go/sync1.(*Pool).Put()
/Users/yanqing11/test/go/sync1/pool.go:108 +0xe8
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func2()
/Users/yanqing11/test/go/sync1/pool_test.go:18 +0x50
Previous write at 0x00c4200ca080 by goroutine 7:
_/Users/yanqing11/test/go/sync1.(*Pool).Put()
/Users/yanqing11/test/go/sync1/pool.go:109 +0x2ad
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func1()
/Users/yanqing11/test/go/sync1/pool_test.go:14 +0x5e
Goroutine 8 (running) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:17 +0x129
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
Goroutine 7 (finished) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:12 +0xfd
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
==================
==================
WARNING: DATA RACE
Write at 0x00c4200ca090 by goroutine 8:
_/Users/yanqing11/test/go/sync1.(*Pool).Put()
/Users/yanqing11/test/go/sync1/pool.go:115 +0x206
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func2()
/Users/yanqing11/test/go/sync1/pool_test.go:18 +0x50
Previous read at 0x00c4200ca090 by goroutine 7:
_/Users/yanqing11/test/go/sync1.(*Pool).Get()
/Users/yanqing11/test/go/sync1/pool.go:141 +0x1ee
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func1()
/Users/yanqing11/test/go/sync1/pool_test.go:13 +0x38
Goroutine 8 (running) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:17 +0x129
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
Goroutine 7 (finished) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:12 +0xfd
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
==================
==================
WARNING: DATA RACE
Read at 0x00c4200ce000 by goroutine 9:
_/Users/yanqing11/test/go/sync1.(*Pool).getSlow()
/Users/yanqing11/test/go/sync1/pool.go:175 +0x17a
_/Users/yanqing11/test/go/sync1.(*Pool).Get()
/Users/yanqing11/test/go/sync1/pool.go:148 +0x243
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func3()
/Users/yanqing11/test/go/sync1/pool_test.go:23 +0x38
Previous write at 0x00c4200ce000 by goroutine 8:
_/Users/yanqing11/test/go/sync1.(*Pool).Put()
/Users/yanqing11/test/go/sync1/pool.go:115 +0x1c6
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func2()
/Users/yanqing11/test/go/sync1/pool_test.go:18 +0x50
Goroutine 9 (running) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:22 +0x155
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
Goroutine 8 (finished) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:17 +0x129
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
==================
--- FAIL: TestSyncAPI (0.00s)
testing.go:730: race detected during execution of test
=== RUN TestSyncAPI2
--- PASS: TestSyncAPI2 (0.00s)
=== RUN TestSyncAPI
--- PASS: TestSyncAPI (0.00s)
=== RUN TestSyncAPI2
--- PASS: TestSyncAPI2 (0.00s)
=== RUN TestSyncAPI
--- PASS: TestSyncAPI (0.00s)
=== RUN TestSyncAPI2
--- PASS: TestSyncAPI2 (0.00s)
=== RUN TestSyncAPI
==================
WARNING: DATA RACE
Read at 0x00c42010a380 by goroutine 36:
_/Users/yanqing11/test/go/sync1.(*Pool).Get()
/Users/yanqing11/test/go/sync1/pool.go:136 +0x5c
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func3()
/Users/yanqing11/test/go/sync1/pool_test.go:23 +0x38
Previous write at 0x00c42010a380 by goroutine 34:
_/Users/yanqing11/test/go/sync1.(*Pool).Put()
/Users/yanqing11/test/go/sync1/pool.go:109 +0x2ad
_/Users/yanqing11/test/go/sync1.TestSyncAPI.func1()
/Users/yanqing11/test/go/sync1/pool_test.go:14 +0x5e
Goroutine 36 (running) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:22 +0x155
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
Goroutine 34 (finished) created at:
_/Users/yanqing11/test/go/sync1.TestSyncAPI()
/Users/yanqing11/test/go/sync1/pool_test.go:12 +0xfd
testing.tRunner()
/Users/yanqing11/dev/go/src/testing/testing.go:777 +0x16d
==================
--- FAIL: TestSyncAPI (0.00s)
testing.go:730: race detected during execution of test
=== RUN TestSyncAPI2
--- PASS: TestSyncAPI2 (0.00s)
=== RUN TestSyncAPI
--- PASS: TestSyncAPI (0.00s)
=== RUN TestSyncAPI2
--- PASS: TestSyncAPI2 (0.00s)
FAIL
FAIL _/Users/yanqing11/test/go/sync1 0.025s
2. the test case using a pointer of Pool, the test case code is also in the
gist.
https://gist.github.com/lrita/efa8c4ae555b4b7cceee29b4ed819652#file-pool_test-go
Thanks for your reply.
在 2018年8月24日星期五 UTC+8下午12:41:17,Dave Cheney写道:
>
> Hi,
>
> Can you please do two things to help with this error report.
>
> 1. Please include the entire data race report -- we need this to match up
> the line with the source code you've provided in the gist
> 2. Please double check that you are not copying a your sync.Pool type by
> value, this can happen if you have a type declared on sync.Pool, not
> *sync.Pool, or it could happen if you do something like this
>
> var x sync.Pool
> y := x
>
> Thanks
>
> Dave
>
> On Friday, 24 August 2018 13:46:10 UTC+10, [email protected] wrote:
>>
>> Hi lan,
>>
>> The sync.Pool has memory accesses in per-p private storage. Why it not
>> reports `DATA RACE`, but it reports when I copy those code outside stdlib?
>> I'm confused about this, or there is something wrong in
>> https://gist.github.com/lrita/efa8c4ae555b4b7cceee29b4ed819652
>> Thanks.
>>
>> 在 2018年8月24日星期五 UTC+8上午4:36:06,Ian Lance Taylor写道:
>>>
>>> On Thu, Aug 23, 2018 at 12:43 AM, <[email protected]> wrote:
>>> > package main
>>> >
>>> > import "runtime"
>>> >
>>> > var a int
>>> >
>>> > func calc() {
>>> > for i := 0; i < 10; i++ {
>>> > go func() {
>>> > for {
>>> > runtime.RaceDisable()
>>> > a++
>>> > runtime.RaceEnable()
>>> > }
>>> > }()
>>> >
>>> > }
>>> > }
>>> >
>>> > func main() {
>>> > calc()
>>> > }
>>> >
>>> > go run -race a.go
>>>
>>> Thanks for the example. As the docs for runtime.RaceDisable say, it
>>> only applies to synchronization events, like mutex locks. It doesn't
>>> apply to memory accesses.
>>>
>>> Ian
>>>
>>>
>>> > 在 2018年8月22日星期三 UTC+8下午10:34:35,Ian Lance Taylor写道:
>>> >>
>>> >> On Wed, Aug 22, 2018 at 3:25 AM, <[email protected]> wrote:
>>> >> >
>>> >> > When I copy the sync.Pool's source code in a repo, and using
>>> >> > `//go:linkname`
>>> >> > link those runtime functions manually.
>>> >> > When I run `go test -race`, it reports `DATA RACE`.
>>> >> > But the sync.Pool with the same test case does not report `DATA
>>> RACE`.
>>> >> >
>>> >> > Does runtime.RaceDisable not work in non-std library ?
>>> >>
>>> >> It should work. I think you'll have to show us your code.
>>> >>
>>> >> Ian
>>> >
>>> > --
>>> > 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].
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>
--
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].
For more options, visit https://groups.google.com/d/optout.