Mutexes aren't expensive when compared to channels. They are usually harder
to get right and that's why there is the old Go mantra:
"Don't communicate by sharing memory; instead, share memory by
communicating."

I would say you should use what fits the use case but prefer channels if
possible.


tis 23 okt. 2018 kl 12:19 skrev 'Reinhard Luediger' via golang-nuts <
golang-nuts@googlegroups.com>:

> Hi folks,
>
> somwhere on my golang journey ("don't k now where and when") I was teached
> that mutexes are very expensive and we should prefer to communicate over
> channels instead of working with mutexes.
> I trusted it until today. I explained it to our aprentice based on my
> knowledge and he asked me  if i can show him the performance difference.
>
> Therefore I wrote this little demo with the expectation that the channel
> solution will beat the mutex one and was really surprised when I saw that
> the mutex based solution beats the channels one most of the time by factor
> 2.
>
> https://play.golang.org/p/Kf9VBSoTLcU
>
> What am I missing here or is it not true anymore that mutexes are so
> expensive that we should prefer Communicating over Sharing.
>
>
> kind regards
>
>
> Reinhard Lüdiger
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to