Hacker News new | ask | show | jobs
by Retr0id 26 days ago
Goroutines are not directly equivalent to threads.
2 comments

If 100 goroutines are handled by 10 threads, the effect on correctness is identical: any two can be running in parallel with each other (not just concurrently). From the point of view of this discussion, that's all that matters.
Correctness is nice but performance characteristics exist too.
They used to not be, because they were cooperatively scheduled and threads can be preempted. But they added goroutine preemption in Go 1.14 so in practice there aren't really any significant differences to threads, at least in semantics. (At least as far as I remember; been a while since I wrote any Go.)

You can be pedantic and say they aren't technically threads but that doesn't really matter from a programming perspective.

Even when goroutines were cooperatively scheduled, because the cooperation was mostly hidden and every function call was a yield point the average developer would treat them as being cooperative... until they spawned too many goroutines with a tight loop (and no function call) and the runtime locked up.

> You can be pedantic and say they aren't technically threads but that doesn't really matter from a programming perspective.

They are technically threads: they are independently scheduled, concurrent units of execution sharing an address space. They're just not OS (or kernel) threads. Hell, technically userspace threads (generally cooperatively scheduled) are the original, they predate kernel threads by a decade or two.