Map with concurrent access

user1243746 picture user1243746 · Jun 16, 2012 · Viewed 71.7k times · Source

When you use a map in a program with concurrent access, is there any need to use a mutex in functions to read values?

Answer

Sonia picture Sonia · Jun 16, 2012

Multiple readers, no writers is okay:

https://groups.google.com/d/msg/golang-nuts/HpLWnGTp-n8/hyUYmnWJqiQJ

One writer, no readers is okay. (Maps wouldn't be much good otherwise.)

Otherwise, if there is at least one writer and at least one more either writer or reader, then all readers and writers must use synchronization to access the map. A mutex works fine for this.