Hacker News new | ask | show | jobs
by DagAgren 2247 days ago
It is not. Coroutines are a much more fundamental feature. They can be used to implement cooperative multitasking, and since that is such a common use case, they have gotten confused with the concept of cooperative multitasking.

Actual coroutines are a lot more flexible and interesting than just cooperative multitasking, though.

1 comments

Erm, I'm pretty sure I can implement coroutines using cooperative multitasking. Also, the other way around. So I'd say they're equivalent in that sense.
Cooperative multitasking usually involves a scheduler. Coroutines are called explicitly, which you can't do through a scheduler.
Now you're really just making claims about implementation details. That doesn't make one concept more "fundamental" or "flexible" than the other, while "interesting" is just a subjective judgement.
I'm not. The scheduler decides what code to execute next, the caller does not. With coroutines, the caller explicitly decides what code to execute next. That's a fundamental difference.
Explicitly selecting what code to execute next can be trivially achieved in a cooperative multitasking system. Naturally, the details work out differently. That's because both concepts are equivalent, just not the same.
Sure, you could implement some kind of anti-scheduler, but that is just plain silly, and really doesn't affect the point at all. You can do anything in any Turing-complete language, but that doesn't mean that Brainfuck is equivalent to Prolog in any way that is actually useful or interesting.
With coroutines, your program logic itself is the scheduler.
Thus why coroutines are more fundamental and powerful.