Home / Learn Chip Programming / What Is an RTOS and When Do You Need One

What Is an RTOS and When Do You Need One

An RTOS runs multiple tasks with deterministic timing. Know the difference from a plain loop.

In shortAn RTOS runs multiple tasks with deterministic timing. Know the difference from a plain loop.

Theory in plain words

Super loop vs RTOSSuper loopwhile(1) calls functions in ordersimple, tinyone slow function delays everythingtiming depends on loop lengthRTOStasks with prioritiespre-emption: urgent task runs nowqueues, mutexes, timersneeds RAM per task stack
Super loop vs RTOS

What it is

A real-time operating system schedules tasks by priority, offers queues, semaphores, mutexes and timers, and guarantees bounded latency. FreeRTOS, Zephyr, ThreadX (Azure RTOS), RT-Thread and embOS are common.

Why we use it

Super-loops become unmanageable with many activities. An RTOS gives structure, but costs RAM, flash and requires care with shared data.

How it works

Split the system into tasks: sensor task, display task, communication task. The kernel switches between them using a timer tick and context switches.

Where it is used

  • Anything with several activities and timing constraints
  • Wi-Fi/BLE products
  • Safety-critical systems

Super loop latency

See how a slow function delays an urgent eventTry it Yourself

In a super loop the worst response time is the sum of all work. With pre-emptive priorities it is only the context switch time.

RTOSLicenceFootprintWhere
FreeRTOSMIT6 to 10 KB flashAWS, ESP32, STM32, most MCUs
ZephyrApache 2.08+ KB, full platformLinux Foundation, Nordic, Intel
Azure RTOS ThreadX / Eclipse ThreadXMIT (open)smallconsumer, industrial
RT-ThreadApache 2.0smallChina, many boards
SafeRTOS / QNX / VxWorkscommercialcertifiedautomotive, aerospace, medical
Tip:You do not need an RTOS for a thermostat. Use one when you have several independent timing-sensitive jobs or a protocol stack that needs blocking calls.

Quick quiz

1. Biggest benefit of RTOS priorities?

2. Which RTOS is MIT licensed and very popular?

Common questions

Biggest benefit of RTOS priorities?

Urgent tasks pre-empt less urgent ones. Latency of important tasks stays low.

Which RTOS is MIT licensed and very popular?

FreeRTOS. Widely used on MCUs.