RTOS Explained: Real-Time Operating Systems for IoT

RTOS explained: what real-time operating systems do, FreeRTOS vs Zephyr, tasks and scheduling, mutexes and queues, and when to use an RTOS in embedded and IoT development.

15
Min Read
Top 200
Kaggle Author
Apr 2026
Last Updated
5
US Bootcamp Cities

Key Takeaways

01

An RTOS Adds Managed Multitasking to Bare Metal

Bare-metal firmware runs one thing at a time — a main loop, with interrupts occasionally breaking in. This works for simple devices. But a modern IoT device might need to: read sensors every 100ms, process Bluetooth packets as they arrive, run a control loop at 1kHz, publish MQTT data every 30 seconds, and handle user button presses — all "simultaneously."

An RTOS (Real-Time Operating System) solves this. It's a small kernel (10-50KB) that runs on the microcontroller alongside your application code. It manages multiple tasks, schedules which task runs when, and provides mechanisms for tasks to communicate safely.

The "real-time" part means the RTOS guarantees timing behavior. A high-priority task will always get CPU within a bounded time after it becomes ready — no surprise delays from other tasks hogging the CPU.

02

Tasks and the Scheduler

A task (also called a thread in some RTOS) is an independent function with its own stack and execution state. The RTOS scheduler decides which task runs based on priority and availability.

Task states in FreeRTOS:

Preemptive priority scheduling — The scheduler runs the highest-priority ready task. If a higher-priority task becomes ready while a lower-priority task runs, the scheduler immediately switches (preempts) to the higher-priority task. This is how RTOS guarantees real-time response.

// FreeRTOS task creation example
void SensorTask(void* pvParameters) {
    while(1) {
        float temp = ReadTemperature();
        // Post to queue for processing task
        xQueueSend(xSensorQueue, &temp, 0);
        vTaskDelay(pdMS_TO_TICKS(100));  // Wait 100ms
    }
}

void NetworkTask(void* pvParameters) {
    float temp;
    while(1) {
        // Block waiting for sensor data
        if (xQueueReceive(xSensorQueue, &temp, portMAX_DELAY)) {
            PublishMQTT(temp);
        }
    }
}

// In main():
xTaskCreate(SensorTask, "Sensor", 256, NULL, 2, NULL); // Priority 2
xTaskCreate(NetworkTask, "Network", 512, NULL, 1, NULL); // Priority 1
vTaskStartScheduler();
03

Inter-Task Communication: Queues, Semaphores, Mutexes

Tasks can't just use global variables to communicate — concurrent access causes race conditions. RTOS provides safe primitives:

Queues — Thread-safe FIFO buffers for passing data between tasks. Producer task pushes; consumer task pops. The FreeRTOS example above uses a queue to pass sensor readings from SensorTask to NetworkTask. Queues are the workhorse of RTOS IPC.

Semaphores — Signaling mechanism. Binary semaphore: 0 or 1. ISR gives the semaphore when an event occurs; a task blocks waiting to take it. Counting semaphore: counts multiple events, used for resource pools.

// Binary semaphore — ISR signals task
SemaphoreHandle_t xButtonSemaphore;

void EXTI15_10_IRQHandler(void) {    // ISR
    if (button_interrupt_pending) {
        BaseType_t xHigherPriorityTaskWoken = pdFALSE;
        xSemaphoreGiveFromISR(xButtonSemaphore, &xHigherPriorityTaskWoken);
        portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
    }
}

void ButtonHandlerTask(void* pvParameters) {
    while(1) {
        // Block until ISR signals
        if (xSemaphoreTake(xButtonSemaphore, portMAX_DELAY) == pdTRUE) {
            HandleButtonPress();
        }
    }
}

Mutex — Mutual exclusion. Prevents two tasks from accessing a shared resource simultaneously. Different from binary semaphore: mutexes have ownership (only the task that took it can give it) and priority inheritance (prevents priority inversion).

MutexHandle_t xUARTMutex;

void TaskA(void* pvParameters) {
    while(1) {
        xSemaphoreTake(xUARTMutex, portMAX_DELAY);  // Lock UART
        printf("Task A: sensor value = %d\r\n", ReadSensor());
        xSemaphoreGive(xUARTMutex);                   // Unlock
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}
04

FreeRTOS: The World's Most Deployed RTOS

FreeRTOS is used in hundreds of millions of devices. Key reasons for its dominance:

FreeRTOS configuration is done in FreeRTOSConfig.h — you enable/disable features at compile time. Heap management is pluggable: heap_1.c (no free), heap_2.c (simple), heap_4.c (best-fit, most common), heap_5.c (multiple memory regions).

05

FreeRTOS vs Zephyr: Choosing Your RTOS

FeatureFreeRTOSZephyr
Footprint~10KB kernelLarger (50KB+, depends on features)
Build systemCMake or IDE-specificWest (meta-tool) + CMake — standardized
Board support~30 officially, many community500+ officially supported boards
NetworkingAdd-on (LwIP, etc.)Built-in (TCP/IP, BLE, WiFi, Thread, Matter)
Learning curveModerate — simpler APISteeper — Linux-like architecture
BackingAmazonLinux Foundation, Intel, Nordic
Best forSimple devices, AWS IoT CoreComplex connected devices, BLE/Matter/Thread
06

RTOS in IoT Applications

A typical IoT device firmware with FreeRTOS might have these tasks:

The RTOS scheduler ensures SensorTask and ControlTask always run on time, while NetworkTask (which blocks on I/O) and lower-priority tasks fill the remaining CPU time.

07

When to Use an RTOS vs Bare Metal

Use Bare Metal WhenUse RTOS When
Single simple functionMultiple concurrent tasks needed
Very constrained MCU (<16KB RAM)Sufficient memory for RTOS overhead
Hard real-time with deterministic control loopMultiple tasks with different rates
Simple ISR-driven design worksComplex inter-task communication
Safety-critical, certified code requiredDevelopment speed matters more than footprint
Reserve Your Seat
08

Frequently Asked Questions

What is real-time in RTOS and how does it differ from a regular OS?

Real-time means the system guarantees tasks complete within specified time deadlines — predictable worst-case latency. Regular OS (Linux) optimizes for throughput, not deadline guarantees. RTOS is used where late response equals failure: airbags, pacemakers, industrial controllers.

FreeRTOS vs Zephyr: which should I use?

FreeRTOS for simple devices, resource-constrained MCUs, and AWS IoT integration. Zephyr for complex connected devices with BLE, WiFi, Thread, or Matter requirements — it has these stacks built in. FreeRTOS is simpler to learn; Zephyr has better long-term support for complex products.

What is a mutex and why is it needed in RTOS applications?

A mutex prevents two tasks from accessing a shared resource simultaneously. Without it, concurrent access corrupts shared data. The task that takes the mutex owns it — others block until it's released. Use mutexes for shared UART, shared I2C bus, shared data structures.

Bo Peng

Founder of Precision AI Academy. Software engineer with embedded systems and IoT development experience. Teaches firmware development and edge AI to working professionals.

The Bottom Line
You don't need to master everything at once. Start with the fundamentals in RTOS Explained, apply them to a real project, and iterate. The practitioners who build things always outpace those who just read about building things.

Build Real Skills. In Person. This October.

The 2-day in-person Precision AI Academy bootcamp. 5 cities (Denver, NYC, Dallas, LA, Chicago). $1,490. 40 seats max. June–October 2026 (Thu–Fri).

Reserve Your Seat
PA
Our Take

RTOS matters more than ever, and almost nobody teaches it.

Real-time operating systems are one of the worst-served topics in tech education in 2026. Almost every university CS program treats them as a footnote in an operating systems class, and almost every bootcamp skips them entirely. Meanwhile, the devices that run real-time operating systems are multiplying fast — medical devices, industrial controllers, automotive ECUs, robotics, drones, satellites, and a growing fraction of edge AI hardware. The gap between demand and supply for engineers who can work on RTOS code is wider than in almost any other specialty.

What makes RTOS work different from regular OS programming is that 'correct' includes 'on time.' A function that returns the right answer in 50 milliseconds when it had to return in 10 is wrong. That shift in mindset — from 'does it work' to 'does it work within the deadline, every time, including under worst-case load' — is the thing most developers have never had to think about and which no amount of Python experience prepares you for. FreeRTOS, Zephyr, and VxWorks are all excellent starting points, and any one of them gives you the mental model.

For an engineer in 2026 looking for a specialty that pays well and has almost no competition, RTOS-adjacent roles in automotive, aerospace, and medical devices are some of the best-kept secrets in the industry. The certification requirements are real (ISO 26262, DO-178C) and they create a moat.

PA

Published By

Precision AI Academy

Practitioner-focused AI education · 2-day in-person bootcamp in 5 U.S. cities

Precision AI Academy publishes deep-dives on applied AI engineering for working professionals. Founded by Bo Peng (Kaggle Top 200) who leads the in-person bootcamp in Denver, NYC, Dallas, LA, and Chicago.

Kaggle Top 200 Federal AI Practitioner 5 U.S. Cities Thu–Fri Cohorts