Does this have to do with the Tokio runtime that more efficiently coordinates the asynchronous code?
Automatically translated.
Does this have to do with the Tokio runtime that more efficiently coordinates the asynchronous code?
Automatically translated.
The potential for a code change or addition to produce unexpected synchronous blocking (potentially with GIL held) _somewhere_ seems really high and I have to imagine it would be very hard to avoid in the context of a real application codebase ...
Executors may execute those state machines on a single thread, or map them to many threads. The latter looks kinda like green threads depending on what your definition of “green thread” is.
the popular libraries like tokio are using something akin to green threads, though people picky about definitions may not agree to that nomenclature.
I think the state machine required to yield, async & await is baked into the language.
But yes, one can implement the Future trait to take finer control.
Regarding the parent’s question, tasks cannot be preempted from their threads. Threads can of course be preempted from their CPU cores by the OS, but if the number of threads equals the number of cores, this will only happen if other processes on the system are competing for CPU time.