by jonathanstrange · 5y ago · 0 comments
There is also one point of critique, I believe that Go got its concurrency primitives wrong. I fear people will hate me for saying this, but I say it because almost every library I've tested that uses lots of goroutines fails or produces some serious concurrency errors at one point or another. Not only are there many race conditions in Go code, there are also many libraries that silently fail. For example, scan Github for parallel directory walkers or check out uses of sync.atomic.
I personally believe that both transactional memory and the actor model are easier to use although it might be harder to implement and make them efficient. I also think that thread local storage and Goroutine identities would have been useful, despite what the language purists say. Generally speaking, I think Go's choices of concurrency primitives are too low level. (I'm not saying there is anything wrong with them per se, just too low-level for most of Go's users, and I'm not excluding myself in this assessment.)
At the end of the day Go's concurrency story is just traditional threads and mutexes, with custom syntax for one particular datastructure.
But, you do get a great runtime race detector & the M:N scheduler, so you can use lots of goroutines w/o blowing out memory, avoiding async hassles.
The M:N scheduler is great, and the ability to easily spin off Goroutines is really nice, but I think most people shouldn't need to manually launch goroutines most of the time. Goroutines should just be an implementation detail.
Concurrency in general, is really hard: hard to express and hard to debug - none of the languages I know do it perfectly. However, I like Go's concurrency primitives & tooling the most. Javascript and Erlang are runners up - for the record, the languages I'm familiar with are Erlang, Go, Python, Java, Javascript and C. I wouldn't know where C# or Rust would fit.