Topics / RTOS & Real-Time Systems / Q3
What are the states of a task?
Short answer: In FreeRTOS a task is Running (executing on the CPU), Ready (able to run, waiting for the CPU), Blocked (waiting for an event or a delay, usually with a timeout), or Suspended (removed from scheduling until explicitly resumed). A deleted task's memory is freed later by the idle task.
create
│
▼
┌───────► Ready ◄──────────────┐
│ │ ▲ │ event / timeout
│ resume │ │ preempted │
│ ▼ │ │
Suspended ◄─ Running ─── wait ──► Blocked
▲ suspend │
└────────────┘ (from any state)
| State | Meaning | How it gets there |
|---|---|---|
| Running | using the CPU (one task per core) | scheduler picked it |
| Ready | could run but a higher or equal priority task is running | created, unblocked, resumed, or pre-empted |
| Blocked | waiting for time or an event | vTaskDelay, waiting on a queue/semaphore/notification, with a timeout |
| Suspended | not schedulable, no timeout | vTaskSuspend(); leaves only via vTaskResume() |
Key behaviours
- A blocked task uses no CPU; that is why tasks should block instead of polling.
- When an event arrives, the task moves to Ready, not directly to Running; it runs only if it has the highest priority among ready tasks.
- A blocked task with a timeout returns to Ready when the timeout expires, and the API call returns an error code (e.g.
pdFALSE,errQUEUE_EMPTY), which the task must check. vTaskSuspendis rarely the right tool for synchronisation: there is no timeout and it is easy to miss a resume. Prefer blocking on an event.
Zephyr names: running, ready (runnable), pending (waiting on an object), sleeping, suspended, dead.
Inspection: vTaskList() / uxTaskGetSystemState() in FreeRTOS, kernel threads in the Zephyr shell, or RTOS-aware debugger views (Ozone, STM32CubeIDE, Tracealyzer).