Comment by menaerus
4 days ago
> Nah, coroutines/async/etc often lives in various threads (ie, the workers can schedule one of them on different threads during the lifetime and they live concurrently), so you still have all the issues of threading (+ new ones since things like thread-local variables aren't reliable if an async/coroutines moves threads between calls).
In cooperative scheduling how is it possible to have two coroutines running concurrently?
You're thinking of older early coroutines or in singlethreaded runtimes (JS).
It's M:N threading, most logical threads/tasks are more lightweight than full OS threads, the logical ones should preferably behave cooperatively but they can be scheduled onto any number of real worker threads (usually these systems picks something like 2x worker threads compared to real CPU/Core count to manage some codepaths not being as well behaved).
Erlang and .NET(with Task/async) uses this model, iirc modern Java does this also (but hides it) and I'd be surprised if the modern async Rust or C++ variations didn't do this as well.
C++20 co-routines model is based on .NET ones, as the original model was proposed by Microsoft and inspired on WinRT work.
If you know how to create asyncable types on .NET, the magic methods expected by C++ compiler will feel familiar.
You mean in the sense that async methods return "awaitable" (Value)Task objects that contains the actual activation machinery that can be queried for liveness status?
It's funny that they're actually revamping the entire machinery for .NET 11 to defer allocations by default for non-waiting codepaths (Not sure, but iirc that machinery might require JIT compilation so would've perhaps not been possible to use for C++).