What to Expect in an RTOS

RTOS Features

In this section, you'll learn about six RTOS features to consider for your next embedded project: determinism, spatial and temporal separation, scheduling, preemptive and cooperative RTOS, memory management, and interprocess communications.

Deterministic RTOS

An RTOS that guarantees a task runs in a specified amount of time is called deterministic. Some RTOSes may guarantee determinism even with unexpected inputs. PX5 RTOS is an example of a deterministic RTOS with submicrosecond context switching and API calls.

rtos deterministic

Spatial vs. Temporal Separation

Spatial separation, or spatial isolation, allows tasks to run in their own private memory spaces. Temporal separation allows tasks to meet timing requirements without interference.

RTOS Scheduling

A scheduling algorithm decides the order in which tasks are run on processing units, so they can each meet their time constraints. A thread is a unit of work that can run concurrently with other threads. RTOS schedulers use priority, absolute and relative deadlines, and state to manage threads:

  • Priority. Threads with higher priority preempt tasks at lower priority when necessary. This allows critical tasks, such as a car's throttle control, to run without being delayed by less important tasks, such as data logging.
  • Deadline. An absolute deadline is the exact time by which a job must be completed. A relative deadline is the maximum allowable completion time.
  • State. A thread is either ready (available for execution), running, or blocked (waiting for an event, such as network data.)

Preemptive or Cooperative Multitasking

Preemptive and cooperative multitasking are two methods an RTOS uses to execute multiple tasks or processes at once. A preemptive RTOS may stop the execution of a task to allocate the CPU to another process. By contrast, in cooperative multitasking, only the task itself can yield control.

RTOS Memory Management

An RTOS divides physical memory into sections, called stack and heap, to share it. The stack stores a function's call information and its local variables, which requires careful management. The heap allocates dynamic memory for global information for sharing. To manage memory effectively, an RTOS uses techniques, such as first-fit and best-fit.

Interprocess Communication (IPC)

Interprocess communication enables processes to synchronize and communicate with each other, such as passing messages and sharing memory. An RTOS enables this communication through queues, semaphores, and mutexes.

Three common communication types that RTOS are:

  • RTOS queues: are first-in, first-out (FIFO) buffers in memory that supports the passing of messages between tasks.
  • RTOS semaphores: signals between tasks that trigger an action by the receiving task.
  • RTOS mutexes: flags used to protect critical sections of code by allowing only one thread to access it at a time.