RTOS
An RTOS (Real-Time Operating System) is an operating system designed to process data and execute tasks with deterministic, predictable timing.
Unlike general-purpose operating systems (GPOS) like Linux, Windows, or macOS—which prioritize high overall throughput and fair execution across applications—an RTOS guarantees that critical tasks complete within strict time bounds (deadlines).
Core Characteristic: Determinism
In an RTOS, speed matters less than predictability.
- GPOS (Linux/Windows): "Execute as fast as possible on average, but a process might occasionally pause for 50ms due to garbage collection, background operations, or fair scheduling."
- RTOS: "Guarantee that Task A will respond to a sensor interrupt within exactly 5 microseconds, 100% of the time, regardless of what else the CPU is doing."
RTOS Classifications
| Type | Definition | Failure Consequence | Typical Examples |
|---|---|---|---|
| Hard Real-Time | Missing a deadline constitutes total system failure. Deadlines are absolute constraints. | Catastrophic safety hazard, loss of life, hardware destruction. | Pacemakers, airbag deployment, flight control fly-by-wire systems, ABS brakes. |
| Firm Real-Time | Missing a deadline renders the output useless, but does not immediately destroy the system. | Severe degradation of service quality or lost data. | Financial algorithmic trading platforms, industrial manufacturing inspection lines. |
| Soft Real-Time | Missing a deadline degrades performance, but the system continues operating normally. | Minor inconvenience, UI stutter, audio drops. | Video streaming buffers, video game frame rendering, digital cameras. |
Key Technical Architectural Features
Preemptive Priority-Based Scheduling
An RTOS kernel assigns fixed numeric priorities to threads. If a high-priority thread moves to the ready state (e.g., triggered by an interrupt), the scheduler immediately interrupts the currently running lower-priority thread without waiting for its timeslice to expire.
Minimal Interrupt Latency
Interrupt handlers (ISRs) are kept extremely short. The RTOS minimizes locked critical sections within its own kernel code so that external hardware events can interrupt CPU execution near-instantaneously.
Priority Inheritance (Preventing Priority Inversion)
A classic RTOS bug is priority inversion, where a low-priority thread holds a mutex needed by a high-priority thread, and a medium-priority thread preempts the low-priority thread—effectively delaying the high-priority thread indefinitely.
Modern RTOS kernels implement Priority Inheritance: the low-priority thread holding the mutex temporarily "inherits" the high priority of the waiting thread until it releases the lock.
Popular RTOS Implementations
- FreeRTOS: Open-source, lightweight kernel widely used in IoT, microcontrollers (ESP32, STM32), and consumer electronics.
- Zephyr: Open-source RTOS managed by the Linux Foundation, targeted at secure resource-constrained IoT devices.
- QNX Neutrino: POSIX-compliant microkernel RTOS used heavily in automotive digital cockpits, ADAS, and medical robotics.
- VxWorks: Commercial RTOS widely deployed in space missions (Mars Rovers), defense, and aerospace systems.
- RT-Linux (PREEMPT_RT): Linux kernel patch set that transforms standard Linux into a soft/hard real-time system by making kernel primitives fully preemptible.