If you have a static map of mutexes, and a map of *Market, then you don't 
need sync.Map - because all of the accesses to the maps are read-only. If 
you are inserting new data sources while the program is running, then you 
*do* want sync.Map.

On Wednesday, 23 February 2022 at 10:43:27 UTC yan.z...@gmail.com wrote:

> The reason why I do not use channel is that not each one market updates 
> is needed, but I need to take samples from time to time.
>

Yes, that's quite possible with a goroutine that manages the market state:
https://go.dev/play/p/4Q8H-Binqc1

You can have as multiple writers and multiple readers.  As long as 
communication is over a channel, and you copy data over the channel rather 
than copying pointers (or implied pointers like slices), then it's all safe 
and race-free.

Another way to enforce the same discipline is if you keep your markets and 
mutexes private, and enforce all access via getter/setter methods.

-- 
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/7d0ab6e3-3f18-46da-b1a3-ae7e469a715cn%40googlegroups.com.

Reply via email to