The short answer
You don’t need an RTOS just because a system is real-time. A well-structured super loop with interrupts handles a lot of embedded products, including some with strict deadlines. An RTOS starts paying for itself when one or more of these is true:
- You have several independent activities with different urgency, and long-running work would otherwise delay urgent work.
- You need a protocol stack, such as TCP/IP, Bluetooth, USB, or a cellular modem library, that expects an RTOS.
- Your code is full of blocking waits, such as waiting for a radio, a flash erase, or a slow peripheral, that are awkward to turn into state machines.
- The project is large enough that separate, independently written modules matter more than squeezing out RAM.
If none of those apply, a super loop, or one of the middle-ground designs below, is often simpler, smaller, and easier to verify.
What a super loop is
A super loop is one infinite loop in main() that calls each piece of work in turn. Interrupts handle the truly urgent events and hand data to the loop through flags or buffers. This is sometimes called a foreground/background design. The interrupts are the foreground, and the loop is the background.
volatile bool adc_ready = false; /* set by the ADC interrupt */
int main(void)
{
hardware_init();
for (;;) {
if (adc_ready) {
adc_ready = false;
control_update(); /* use the new sample */
}
comms_poll(); /* handle UART bytes, if any */
ui_poll(); /* buttons and display */
watchdog_kick();
}
}
The Arduino setup() and loop() model is a super loop. So is most simple bare-metal firmware.
Strengths: the code is easy to follow, has no hidden context switches, uses one stack, and has a small footprint. Execution order is fixed and visible.
Weaknesses: every function in the loop has to return quickly. One slow function delays everything else, and anything that needs to wait must be rewritten so it doesn’t block.
What an RTOS gives you
An RTOS lets you write each activity as its own task, with its own stack and a priority. Tasks can block, which means waiting for time to pass, for data in a queue, or for a signal from an interrupt, without holding up the CPU. A preemptive scheduler always runs the highest-priority task that’s ready.
void control_task(void *arg)
{
for (;;) {
wait_for_adc_sample(); /* blocks until the ISR signals */
control_update();
}
}
void comms_task(void *arg)
{
for (;;) {
message_t msg = wait_for_message(); /* blocks on a queue */
handle_message(&msg); /* may take a while */
}
}
Each task reads like a simple sequential program. If handle_message() takes 20 ms, the control task still runs as soon as its sample arrives, because it has a higher priority and preempts the comms task.
The real difference: worst-case response time
The most useful way to compare the two is to ask how long urgent work can be kept waiting in the worst case.
- In a super loop, work done inside the loop may wait for one full pass of the loop before it gets a turn, in the worst case. If the slowest pass, with every function taking its longest path, is 15 ms, any loop-level job can be delayed by up to about 15 ms. Adding a feature anywhere in the loop makes every other job’s worst case longer.
- With a preemptive RTOS, a high-priority task waits only for interrupts, higher-priority tasks, and any time it’s blocked on a shared resource, plus a small amount of kernel overhead. Adding a low-priority feature doesn’t change the high-priority task’s worst case, provided the two don’t share locks.
Interrupts give a super loop much of the same benefit for very short jobs. The limit is that ISRs must stay short. Once urgent work is too long or too complex to sit in an ISR, the super loop’s worst case starts to matter.
This is the same idea behind priority-based scheduling theory. For how priorities are assigned and checked, see real-time scheduling and multitasking in embedded systems.
The middle ground
The choice isn’t strictly “plain loop” or “full RTOS”. Several designs in between are common and often enough.
- Non-blocking state machines. Each module keeps its own state and does a small slice of work per call, never waiting. A UART parser handles whatever bytes are available, and a flash driver starts an erase and checks back later. This keeps the loop pass short.
- Cooperative or time-triggered schedulers. A timer tick drives a small table of functions, each run at its own period, such as every 1 ms, 10 ms, or 100 ms. Each function must finish quickly. These are very predictable and easy to analyze, which is why they’re popular in safety-related designs.
- Event-driven frameworks. Modules become “active objects” that react to events from a queue and run each event to completion. Frameworks such as Quantum Leaps’ QP follow this model. They can run on bare metal or on top of an RTOS.
- Interrupt priorities as a scheduler. On microcontrollers with nested interrupt priorities, such as Arm Cortex-M, you can push urgent but longer work into a low-priority software-triggered interrupt. This gives you preemption without a kernel. It works, but it gets hard to manage beyond a few levels.
When a super loop is the better choice
- Very small microcontrollers. With a few kilobytes of RAM, separate stacks for several tasks may simply not fit.
- A handful of simple, fast jobs. If every job finishes in microseconds and the slowest loop pass fits comfortably inside your tightest deadline, an RTOS adds little.
- Strict verification needs. A fixed loop or time-triggered schedule is easier to analyze and to argue about in a safety case. Some teams avoid preemption entirely for this reason.
- Lowest possible power with simple behavior. A loop that sleeps until the next interrupt is easy to make very efficient. RTOSes can do this too, for example with tickless idle, but it’s more to configure.
- Learning and prototyping. Simple firmware is easier to reason about while you’re still learning the hardware.
When you probably need an RTOS
- Protocol stacks. Bluetooth, Wi-Fi, TCP/IP, USB, and similar stacks are usually built around threads, queues, and timeouts. Many vendor SDKs, such as Espressif’s ESP-IDF and Nordic’s nRF Connect SDK, are built on an RTOS (FreeRTOS and Zephyr, respectively), so the question is already answered for you.
- Mixed urgency with long jobs. A control loop that must run every millisecond, alongside a file system write that takes 50 ms or a display redraw that takes 30 ms.
- Lots of waiting. Code that waits on modems, sensors with long conversion times, or responses from other devices is much clearer as blocking tasks than as nested state machines.
- Team size and modularity. With several developers, tasks with clear interfaces such as queues let people work on separate modules without tuning a shared loop.
- Middleware you want to reuse. File systems, logging, shells, and update agents often assume an RTOS.
What an RTOS costs you
- RAM. Each task needs its own stack, often a few hundred bytes to a few kilobytes, plus a control block. This is usually the biggest cost on small parts. Sizing those stacks well is a skill in itself; see how to size RTOS task stacks and detect stack overflow.
- Flash. A small kernel typically adds a few kilobytes to a few tens of kilobytes, depending on the RTOS and the features enabled.
- Concurrency bugs. Race conditions on shared data, deadlocks, and priority inversion don’t exist in a single-threaded loop. You’ll need mutexes, queues, and discipline. See RTOS task synchronization and inter-task communication.
- Harder debugging. Bugs can depend on timing and disappear under the debugger. RTOS-aware debuggers and trace tools help a lot, but they’re one more thing to learn.
- Configuration and integration. Tick rate, interrupt priorities, heap model, and hooks all need setting correctly. Interrupt priority mistakes are a classic source of crashes on Cortex-M.
- Certification effort. For safety-related products, you may need a pre-certified RTOS or extra evidence about the kernel’s behavior.
Signs you’ve outgrown your super loop
- You keep adding flags, counters, and “only every Nth pass” logic to spread work across loop passes.
- Adding a feature in one module changes timing somewhere unrelated.
- You’ve had to split a simple sequence, such as “send command, wait, read reply, retry”, into a state machine with many states just to avoid blocking.
- Your interrupt handlers are growing because the loop can’t respond fast enough.
- You’re measuring the worst-case loop time and it’s getting close to your tightest deadline.
A quick decision checklist
Answer these in order:
- Does your SDK or protocol stack require an RTOS? If yes, use it.
- Can every job in the loop finish quickly, with the slowest full pass well inside your tightest loop-level deadline? If yes, a super loop is likely fine.
- Can the long jobs be broken into non-blocking steps without making the code hard to follow? If yes, consider state machines or a cooperative scheduler.
- Do you have the RAM for one stack per independent activity, with margin? If not, stay bare metal or reduce the number of tasks.
- Is the software large, multi-person, or likely to grow a lot? If yes, an RTOS’s structure is often worth its costs.
If you decide on an RTOS, FreeRTOS vs Zephyr vs ThreadX compares the most common open-source options.
Moving from a super loop to an RTOS
You don’t need to rewrite everything at once.
- Start with the loop as one task. Put the existing super loop inside a single low-priority task. Behavior is the same, but you now have a scheduler.
- Pull out the most urgent work. Move it into a higher-priority task that blocks on a notification from its ISR.
- Pull out the slowest blocking work. Move communication or storage into its own task so it can wait without stalling anything.
- Replace shared flags with queues or notifications. That makes data handoff between tasks explicit and safe.
- Measure stacks and timing as you go. Check stack high-water marks and response times after each step.
A hands-on starting point is getting started with FreeRTOS: your first tasks on a microcontroller.
Frequently asked questions
Can a super loop be hard real-time?
Yes. If the worst-case loop pass and interrupt load are bounded and fit inside every deadline, a super loop meets hard deadlines, and it can be easier to analyze than a preemptive system. Many control systems are built this way.
Is Arduino a super loop?
Yes. loop() is called repeatedly from a hidden main(). Some boards, such as ESP32-based ones, actually run loop() inside a FreeRTOS task, so an RTOS is available if you want it.
How much RAM does an RTOS need?
It depends on the RTOS, its configuration, and above all on the number of tasks and their stack sizes. The kernel itself can be small. The stacks are usually what fills RAM, so count tasks and estimate their stacks before deciding.
Should I use embedded Linux instead of an RTOS?
Linux suits larger processors with an MMU and plenty of RAM, when you need rich networking, file systems, or graphics. It’s a different class of system. For small microcontrollers and tight, predictable timing, a super loop or RTOS is the usual choice, and many products combine a Linux processor with a microcontroller that handles the time-critical work.