‹ BackHN Continuity

Thread

Go Concurrency Distilled

402 points · 187 comments · chmaynard

  1. SamInTheShell · · focus · HN ↗
    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.

    1. osigurdson · · focus · HN ↗
      >> in terms of how things can end up happening in any thread

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

      1. dlisboa · · focus · HN ↗
        No. Preemptive scheduling plus M:N mapping combination that Go has is not common in other major implementations.

        Other languages and their implementations of green threads usually have cooperative scheduling or M:1 mapping

        1. dwattttt · · focus · HN ↗
          I'm curious; using hardware threads is M logical threads preemptively scheduled on N physical cores. In what way does this not satisfy the original criteria?
          1. dlisboa · · focus · HN ↗
            That's just not what is referred to as green threads.
            1. dwattttt · · focus · HN ↗
              Yes, in implementation they are not. I'm curious what the difference in subjective experience is.
              1. falserum · · focus · HN ↗
                Green threads don’t allocate stack frames and do not require such a massive context switch, which in turn allows for many more threads.
                1. LtWorf · · focus · HN ↗
                  But if you happen to call a blocking syscall everything breaks.
                  1. jeremyjh · · focus · HN ↗
                    That is not true of preemptive green threading systems. Go/Erlang/Haskell all run native foreign code on its own threads, and manage all internal I/O with async schedulers that never block. They also preempt user code in tight loops.

                    Those are the only mature languages that have all of these features.

                    1. gf000 · · focus · HN ↗
                      Not sure if purposefully but you left out java. It doesn't preempt a CPU hot loop, but arguably you don't really want to disturb the CPU there / the whole "green thread" model doesn't make much sense with that kind of workload. That's why you have ordinary threads as well.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.