> What if you are writing to a value in the map? Surely that is safe to do concurrently with other processes reading at least.
Nope. You need to protect your state by communicating with channels or using a lock.
> What if you are writing to a value in the map? Surely that is safe to do concurrently with other processes reading at least.
Nope. You need to protect your state by communicating with channels or using a lock.
But what are you protecting? Setting a value will not cause a map rebalance, and so long as you are just setting a new value (not incrementing or like) it should be an atomic operation. Locking is really slow, and if you can find safe ways to avoid it, it can be a good thing.
The hash map first needs to determine whether it already has a value with such a key or not, which requires some checking that typically involves many instructions and is not atomic. And to determine that, you at least need a read-lock.