‹ 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. gf000 · · focus · HN ↗
                    That's why higher level languages are in an advantage. E.g. in java - outside of FFI - syscalls are basically "only within" standard library functions. So it was possible to make them virtual thread aware, e.g. park a virt thread, use something like io uring for the actual IO call on the JVM level and resume it when it returns, doing work on another virt thread in the meanwhile.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.