2 ms·
I too ended up replacing all channels with a mutex or two in a small web socket relay server in Go, and things became 10x easier to reason about. I think part
by lastofus 9y ago
I too ended up replacing all channels with a mutex or two in a small web socket relay server in Go, and things became 10x easier to reason about.
I think part of the problem is the lack of usage/support for channels in the Go stdlib itself (seems that the stdlib authors also prefer mutexs). The other issue with sending a close msg on a channel to let the consumer know there will be no more messages, and that an error is thrown if you write to a closed channel.
- civility 9y agoIf you can reduce everything to _one_ mutex, that's simple. As soon as you have two mutexes, you need to start worrying whether one thread grabs A then B and another grabs B then A. In larger projects with multiple people contributing, the mutex and condvar approach does not scale well. It's very easy to get difficult to reproduce race conditions.