Go Concurrency Distilled

(antonz.org)

28 points | by chmaynard 10 hours ago

1 comments

  • SamInTheShell 54 minutes ago
    The concurrency and threading in Go just feels like magic compared to every other language. I'm a goroutine addict and I refuse to be rehabilitated.

    Just from observations over the years, I don't think there's any other language quite like this, in terms of how things can end up happening in any thread.

    • osigurdson 5 minutes ago
      >> in terms of how things can end up happening in any thread

      Doesn't that describe pretty much any green thread style concurrency implementation.

    • kccqzy 6 minutes ago
      I learned Haskell before that, and frankly the concurrency in Go feels similar, but is a definite downgrade due to the lack of STM. (You can implement channels and select using STM, so these don’t have to be in the standard library.) The concurrency design in Haskell feels like true magic.
    • chimbambum 50 minutes ago
      any downsides to it in your experience?
      • unscaled 31 minutes ago
        Managing channels and making sure they are closed just once is quite messy compared to other languages. The Go channel axioms[1] don't make much sense: why does closing a channel multiple times panic, but reading from a closed channel returns a zero value?

        Kotlin gets this right. On send/receive, you can use trySend or tryReceive if you want to avoid exceptions. Considering Kotlin also has coroutines and structured concurrency, concurrency in Kotlin feels more ergonomic to me than Go. At least if you want to get concurrent code with least amount of bugs and not just least amount of extra keywords.

        [1] https://dave.cheney.net/2014/03/19/channel-axioms

        • Groxx 16 minutes ago
          Yeah, channels are the main pain point. In addition to the axioms being simply weird (because it's an easy set to implement), another major problem is that you're essentially forced to use them because they're the only things that can work with `select`, and that's the only reasonable option for many operations. Especially if you touch other code, like the stdlib.

          That and the lack of tooling around mutex usage / concurrency correctness. The race detector is legitimately excellent and every language needs it, but it can only catch races that you trigger in tests/builds with it enabled, and few projects write anywhere near sufficient concurrent tests to catch issues in practice. There isn't even a "this var claims to be protected by lock X, but it is not held [here]" lint, or "this var is atomic but used non-atomically [here]" (though this one is significantly less of an issue with generics, as safe zero-cost abstractions now exist).

      • Joel_Mckay 29 minutes ago
        Go and Julia are fun languages.

        In production, Go has proven solid for several years. It is best when used with the native code people ported.

        There are only two issues I encountered:

        1. getting the legacy ancient C source meta-circular Go compiler working to port the Go boot-strap compiler upgrade chain is a kick in the pants. However, once it is on a architecture it has proven rather resilient.

        2. memory limited systems can develop reliability issues, as Go programs will often ungracefully throw hard to diagnose unrelated errors during each crash. A good metric is 3:1 of your average load as a safety margin (if you see 2GiB in average RAM use, make sure to over-provision the host with 8GiB RAM etc.)

        Other than the above short list of edge cases, if you join a pure Go project it is usually pretty reliable. Most community folks interested in the language seem fairly competent at building stuff that is fun. =3