The go race detector complains about my code in a way that makes no sense to me, but I guess that the authors of the race detector know more about this than I do.
I have this closure:
func(f *datastore.F) bool {
a, ok := (*f).(*datastore.T)
...
}
that I pass as an argument to this function:
func GetFunc(f func(fid *datastore.F) bool) (*datastore.F, bool) {
kvs.lock.RLock()
defer kvs.lock.RUnlock()
for _, v := range kvs.fs {
if f(v) {
return v, true
}
}
return nil, false
}
and this is the relevant part of the other goroutine:
for read := range [chan of datastore.F] {
s.lock.Lock()
s.fs[read.Fi()] = &read
s.lock.Unlock()
}
kvs
is an instance of this type:
type kvstore struct {
lock sync.RWMutex
fs map[datastore.Fi]*datastore.F
}
datastore.F
is an interface, and *datastore.T
implements that interface.
The race detector complains that the closure and the other goroutine have a data race. The other goroutine writes and the closure reads. What I don't see is how this could conflict, given the sync.RWMutex
in place.