The race detector has many special cases for packages like sync and runtime, so it can detect synchronization operations. I haven't looked, but I wouldn't be surprised if the race detector ignored package sync's code bodies and just hard coded the semantics of each operation.
On Monday, April 29, 2019 at 8:18:39 PM UTC-7, jacki...@gmail.com wrote: > > On line 85 in > https://github.com/golang/go/blob/release-branch.go1.12/src/sync/mutex.go , > the code " old := m.state " is weired because m.state is read and write > by different goroutine. > Why it can't be detected by race condition detector. > > > I write a function Test with race condition problem. > If put it in src/sync/mutex.go, it can't be detected. > If put it in other package like os.go, it can be detected. > That's weired, anyone has some idea ? > > > package main > import( > "sync" > "os") > func main(){ > sync.Test() // race condition will not detect > os.Test() // race condition will detect} > > > > func Test(){ > a := int32(1) > > if race.Enabled { > race.Acquire(unsafe.Pointer(&a)) > } > > go func(){ > atomic.CompareAndSwapInt32(&a, 1, 4) > }() > _ = a} > > -- 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. For more options, visit https://groups.google.com/d/optout.