←back to thread

Go channels are bad

(www.jtolds.com)
298 points jtolds | 2 comments | | HN request time: 0.404s | source
Show context
Jabbles ◴[] No.11210740[source]
Effective Go has always said:

Do not communicate by sharing memory; instead, share memory by communicating.

This approach can be taken too far. Reference counts may be best done by putting a mutex around an integer variable, for instance.

https://golang.org/doc/effective_go.html#sharing

replies(3): >>11210862 #>>11210978 #>>11210990 #
api ◴[] No.11210978[source]
I thought Go had gc. Why would you ever need reference counts?
replies(2): >>11211015 #>>11211294 #
1. chrsm ◴[] No.11211294[source]
Example: Recently built a small service that responds to requests and walks various files looking for data.

The service can be asked to unload (close) the file, but it's hard to say whether it's in-use at the time without some kind of reference count to current requests using the file.

replies(1): >>11211343 #
2. nly ◴[] No.11211343[source]
That's kinda what dup() is for. Reference counting happens in the kernel.