Tasks hand back control
Under cooperative scheduling, a running task keeps the CPU until it voluntarily yields control back to the scheduler. The scheduler never interrupts a task on its own; it waits for the task to reach a yield point, such as an await, a sleep, or an explicit yield call.
Why it can be efficient
- Cheap switches because the task chooses the moment, so its state is at a clean boundary.
- Fewer surprises since shared data is not touched mid operation by a sudden switch.
- Simple state as a task knows it runs uninterrupted between its own yield points.
The starvation risk
The danger is a task that does heavy work and never yields. Because nothing forces it off the CPU, every other task on that thread starves, waiting forever. A tight loop with no await point can freeze a whole event loop. This is why cooperative systems urge breaking long work into chunks or offloading it so yield points stay frequent.
Key idea
Cooperative scheduling lets tasks run until they choose to yield, giving cheap clean switches but risking starvation if one task never hands control back.