Updating existing keys in parallel is not guaranteed to be safe. If you
want to modify values, you'd have to do the trick mentioned above where
instead of a map[K]T you use a map[K]*T and to do modification you do *m[k]
= T{...} or whatever.
Go maps do incremental growth work on every update, s
On Tue, Aug 2, 2022 at 7:59 PM burak serdar wrote:
> What exactly do you mean by "read/write 5 different keys"?
>
> If you have a map[int]*SomeStruct, for instance, and if you initialize
> this map with some entries, and then if you have multiple goroutines all
> performing lookups of distinct ke
What exactly do you mean by "read/write 5 different keys"?
If you have a map[int]*SomeStruct, for instance, and if you initialize this
map with some entries, and then if you have multiple goroutines all
performing lookups of distinct keys and modifying the contents of
*SomeStruct, it would be safe
Go maps are only concurrent safe if all accesses are reads (lookups) after
the map is initialized. So your scenario is not safe and can result in a
panic as well as other undefined behavior. The Go standard library has a
concurrent safe map implementation (see https://pkg.go.dev/sync#Map). There
ar
Hi! If I have several 5 goroutines read/write 5 different keys in map
independently without a Mutex/RWMutex. Each goroutine just read/write their
own corresponding key. No intersection.
In such a case, no goroutines will operate on the same key, does that mean
it's safe?
Or maybe each goroutin