12 ms·
(I don't know about performance differences) > I've seen a golang informal chat where one of the golang team member advertized using mutex instead of having a
by slimsag 12y ago
(I don't know about performance differences)
> I've seen a golang informal chat where one of the golang team member advertized using mutex instead of having a huge select, but i wonder if anyone has real experience of the two here.
My "real experience" here, and the opinion of other Go users I've talked with is that you should use the right tool for the right job.
Channels are awesome and open room for a lot of interesting opportunities. Something interesting I've done is using channels of functions (closures) to have OpenGL code sent over a channel to run on the main thread (see [here](http://slimsag.blogspot.com/2014/11/go-solves-busy-waiting.html) http://slimsag.blogspot.com/2014/11/go-solves-busy-waiting.h...). That is a one-off/odd example by many, but it shows how versatile they really are.
Sometimes using a mutex makes the code cleaner, though. I wouldn't use a channel to just protect a single variable shared by multiple goroutines, for instance. A mutex may make more sense in a lot of situations, lo and behold, if it does then just use a mutex then.