We’re Officially Live β€” Lifetime Founding Membership Available for a Limited Time
Free preview

Bare-Metal vs RTOS

When the super-loop stops scaling: what an RTOS buys you (tasks, priorities, blocking that yields), what it costs (RAM, complexity, concurrency bugs), and when bare-metal is still the right call.

20 min read

In this lesson:

This module builds on Embedded Fundamentals (interrupts, timers, the boot sequence).


Bare-metal: the super-loop

The simplest firmware is bare-metal: no operating system, just a while(1) super-loop plus interrupt handlers.

int main(void) {
    init();
    while (1) {
        read_sensor();      // each runs in turn, top to bottom, forever
        update_display();
        handle_buttons();
        log_over_uart();
    }
}

It's wonderful when it fits: tiny, no kernel overhead, fully deterministic, easy to reason about. But it strains as you add concurrent activities with different rates and priorities:

You can push the super-loop far with interrupts and state machines, but eventually the juggling becomes unmanageable.


RTOS: tasks with a scheduler

A Real-Time Operating System lets you write each activity as an independent task (a function with its own stack), and a scheduler decides which task runs when, giving each task the illusion of its own CPU.

// Each activity is its own task; the scheduler interleaves them by priority.
void sensor_task(void *arg)  { for (;;) { read_sensor();   vTaskDelay(1); } }
void display_task(void *arg) { for (;;) { update_display(); vTaskDelay(20);} }
 
int main(void) {
    xTaskCreate(sensor_task,  "sensor",  256, NULL, 3, NULL);  // higher priority
    xTaskCreate(display_task, "display", 256, NULL, 1, NULL);  // lower priority
    vTaskStartScheduler();   // never returns; the scheduler takes over
}

The wins:


What it costs

An RTOS is not free:

 super-loop:  everything serialized, one stack, no kernel β€” simple but rigid
 RTOS:        tasks interleaved by priority, N stacks + kernel β€” flexible but heavier

When you need one (and when you don't)

Reach for an RTOS when:

Stay bare-metal when:

The middle ground handles a surprising amount: a super-loop driven by interrupts (fast events in ISRs) feeding ring buffers, with logic as state machines (the DSA/FSM lesson). Many shipping products never need an RTOS. Reach for one when the concurrency genuinely warrants it, not reflexively.


Gotchas


TL;DR

This is just the start

Sign up free to track progress on this lesson, get coding problems with the Run button, and unlock the full interview Q&A.

More in RTOS & Real-Time Concepts

Tasks & the SchedulerPreemptive vs Round-Robin Scheduling
Context Switching
Mutexes & Semaphores
Queues & Inter-Task Communication
Priority Inversion