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.

If you have multiple goroutines adding/removing keys from the map, that
would not be safe.

It would be interesting to know if rewriting existing distinct keys from
multiple goroutines would be safe or not.



On Tue, Aug 2, 2022 at 7:31 PM ag9920 <jingong.w...@gmail.com> wrote:

> 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 goroutine just write to its corresponding key once, with no
> read, will that be safe?
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/76788485-6809-4397-bf94-536a0d0bf0b3n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/76788485-6809-4397-bf94-536a0d0bf0b3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqq50NX8WGGkPK%2BhRSz91QpUHzWWhMmz1c8RNKpa9dncZg%40mail.gmail.com.

Reply via email to