LOGBOOK

HELP

Quiz Entry - updated: 2026.09.25

How does cooperative scheduling with a background time tick work, and what must each task do for it to work?

A timer tick keeps track of time; the scheduler loop checks each task and runs it only when its interval has elapsed. Tasks are never interrupted, so each must do a short piece of work and return quickly.

The cooperative scheduler loop: run each task only when its interval has elapsed, then record when it ran.

* The cooperative scheduler loop: run each task only when its interval has elapsed, then record when it ran. *

This is the scheduler many embedded developers actually use. It improves on the plain super loop with a time base:

  1. Read the system time, maintained by a timer interrupt (the tick, e.g. every 1 ms).
  2. Set the task index to 0 and walk through the task table.
  3. For each task, calculate the elapsed time since it last ran.
  4. If the elapsed time is at least the task's interval, run the task and store the tick at which it ran.
  5. Move to the next task; when all are checked, start again.

Now tasks can be periodic (a sensor every 100 ms, a display every 500 ms), code is split into separate task functions, and interrupts handle urgent events in the background. The scheduler decides what code runs and when.

The limit is in the name: it is cooperative. Nothing can preempt a running task, so a task that takes 50 ms delays every other task by 50 ms. The contract is that each task does a small slice of work and returns, never waiting or looping inside.

Tip: cooperative = tasks give the CPU back; preemptive = the scheduler takes it.

Go deeper:

From Quiz: SIOT / Real-Time Operating Systems and Task Scheduling | Updated: Sep 25, 2026