▲ | nromiun 2 days ago | ||||||||||||||||||||||||||||||||||||||||
Both basically. Another beauty of M:N green threads is that you don't need to differentiate between IO and CPU bound tasks. If you add all those rules to coroutines you are halfway to preemptive scheduling already. And maybe async is not the answer if it still needs more work and tooling after all these years. | |||||||||||||||||||||||||||||||||||||||||
▲ | Phil_Latio 2 days ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||
No i meant cooperative green threads, not the stackless async/await model. My model would basically mean: No "function coloring", all functions can be called as usual. IO related functions will automatically yield, no problem. All CPU-bound work either need manual yield points (not good, I agree) or should be offloaded to a coroutine on a different thread and then awaited (yes with await keyword) cooperatively. If you want to invoke a click handler for an UI, you can launch a coroutine on the same thread (cooperative). Go must do all sorts of trickery with the preemption. Like inserting yield points or even depend on signals so it can preempt a goroutine which didn't hit a yield point. It basically replicates what the OS does with threads. | |||||||||||||||||||||||||||||||||||||||||
|