On Sunday, 27 June 2021 at 10:32:22 UTC+1 ro...@campbell-lange.net wrote:

> By the way, as a golang newbie, it isn't clear to me when it is advisable 
> to 
> use a channel for locking as opposed to a mutex. Do people tend to use the 
> former? 
>
>
There is an absolutely excellent video on this topic by Rob Pike here:
https://www.youtube.com/watch?v=5zXAHh5tJqQ

Once you've seen these patterns, you likely won't want to go back to 
mutexes.

For example: in your case, I'd create a one-element buffered channel 
containing the data.  Any function which wants to access that data can pop 
the value off the channel, use and/or modify it, then push it back into the 
channel when done.

However if the *only* issue is around concurrent access to a single map, 
then you could just use sync.Map <https://golang.org/pkg/sync/#Map>.

-- 
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/38490f3a-2e62-465b-b03e-a62ec1364088n%40googlegroups.com.

Reply via email to