News for hackers. Stuff that matters.
Re:Go concurrency patterns by jkn on Thursday January 17, 2013 @01:49PM (#5074346)
Very valid concerns I think, but it's not quite that bad. A few points:

- Goroutines are not garbage collected.

- In this case and many others, you can just use a buffered channel. But of course in many other cases it doesn't solve the problem.

- If you solve this with a "quit" channel but don't use it, obviously you have a problem

- Several goroutines can try to send to the same "quit" channel. Make it buffered and have every goroutine try to send.

- In the case of several listeners, you can just close the channel and all receivers will return.

- However if you have several senders and several receivers on the "quit" channel, then you have a problem: closing a closed channel will panic.

See also:

https://groups.google.com/forum/?fromgroups=#!msg/golang-nut...

https://groups.google.com/forum/?fromgroups=#!msg/golang-nut...

There are no comments on this comment yet.