type Foo struct { sync.RWMutex data map[string]bool } o := &Foo{} 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 <a...@cpu.host> wrote: > > 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 the former example is correct. > > Thanks for your advice. > > -- > 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. > -- 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.