Comment by osigurdson
1 day 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.
1 day 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.
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
C# and Rust (via Tokio) both have M:N threading. They both use a work-stealing algorithm to map many tasks onto a finite thread pool. But you're correct that they are cooperative via async/await, not pre-emptive.
I feel like you can't describe something as m:n when it the m uses async/await and doesn't actually have a green thread?
2 replies →
Very curious how much Go wins by this. How worse would typical Go programs run with pre-emption disabled?
2 replies →
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?
They are still full OS threads: they have a full-size stack and have all the same overheads for context switching. Why would you think that a marketing term for a CPU feature is equivalent to an M:N scheduler?
A "hyperthread" can schedule work for two OS threads simultaneously on a single core. An M:N scheduler will schedule millions of green threads on as many cores/hardware threads as you give it (typically you'd give it all of them).
That's just not what is referred to as green threads.
6 replies →
Haskell had preemptive M:N green-threading before Go was invented.
I believe Go didn't originally have it, and added it in 2020, 14 years after Haskell.
Before that, Go did preempt on function calls. Haskell preempts on memory allocation. There is no idiomatic Haskell code that loops without allocating, but it is possible. Go code that loops without function calls is probably a lot more common but still avoidable.
I wasn't comparing Go to every language ever, just the ones people are most likely to pick. In that group Go (and Elixir) have more unique concurrency models.
Java's virtual threads are M:N.
>> Preemptive scheduling plus M:N mapping
AFAIK, in the current implementation, Java's virtual threads yields only when they block (cooperative). But the spec allows a JVM to implement them as preemptive.
1 reply →