Comment by cratermoon

1 year ago

The Go folks will repeat the aphorism, "Do not communicate by sharing memory; instead, share memory by communicating."[1]. The author directly violates the intention of the designers of Go by talking about shared file handles and other data structures, i.e. memory.

The word "channel" doesn't appear a single time in the article, even though goroutines without channels to communicate with each other should never be sharing data. Channels are the synchronization primitive in Go.

1. https://go.dev/blog/codelab-share

A file descriptor is nothing but a pointer. It's really just an int. Usually maintained by the OS.

Instead of sharing the file descriptor across a goroutine (bro, like WTF), let one go routine manage the file descriptor itself.

Channels would help but the author is saying they're naively shared through a closure and that's a problem, no?