RTOS task state

Hyunwoo ChoiHyunwoo Choi
2 min read

In a real-time operating system (RTOS), typically, many tasks are created and run by a scheduler. The task state represents the various stages a task can be in during its lifecycle. The task states can be divided into two different groups: Running state and Not-running state(Suspended, Ready, Blocked).

  1. Ready State: A task in the ready state is prepared to execute but is waiting for the scheduler to allocate CPU time to it. It has all the necessary resources and is waiting in the task queue for its turn to run.

  2. Running State: When a task is assigned CPU time by the scheduler, it enters the running state. The task's code is actively being executed by the processor.

  3. Waiting or Blocked State: A task can enter a waiting or blocked state when it is unable to proceed further due to some condition. This can occur when a task is waiting for an event, such as a signal, semaphore, or data from another task or an external device. In this state, the task is temporarily suspended and does not consume CPU time until the condition is fulfilled.

  4. Suspended State: Tasks can be suspended voluntarily or by the system. When a task is suspended, it is temporarily halted, and it does not run or participate in the scheduling until it is explicitly resumed.

Reference state transition image

RTOSs provide mechanisms to manage and transition between these task states. The scheduler determines which task to run based on priorities, preemption, and scheduling policies.

0
Subscribe to my newsletter

Read articles from Hyunwoo Choi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hyunwoo Choi
Hyunwoo Choi