Fwd: [go-nuts] Correct use of Mutex

2016-10-04 Thread Pietro Gagliardi
> Begin forwarded message: > > From: Pietro Gagliardi <andl...@lostsig.net> > Subject: Re: [go-nuts] Correct use of Mutex > Date: October 3, 2016 at 4:22:34 PM EDT > To: a...@cpu.host > > Why are you locking on the map key? > >> On Oct 3, 2016, at 2:53

Re: [go-nuts] Correct use of Mutex

2016-10-03 Thread Edward Muller
type Foo struct { sync.RWMutex data map[string]bool } o := {} o.Lock() o.data[i] = true o.Unlock() elsewhere o.RLock() v := o.data[i] o.RUnlock() On Mon, Oct 3, 2016 at 11:55 AM wrote: > > Which is correct? > > o.Lock() > o.data[i] = true > o.Unlock() > > or > >

[go-nuts] Correct use of Mutex

2016-10-03 Thread alex
Which is correct? o.Lock() o.data[i] = true o.Unlock() or o.Lock() i.RLock() o.data[i] = true i.RUnlock() o.Unlock() The latter actually seems to help high contention R/W operations on a very large map according to the guy in my team who was working on the problem, but I would have thought