Real-Time Systems and RTOS

Real-Time Embedded Systems Explained

Real-time embedded systems explained: what makes a system real-time, how it differs from a plain embedded system, and how real-time software is built.

On this page
  1. What is a real-time embedded system?
  2. Embedded system vs real-time system
  3. Key timing concepts
  4. Hard, firm, and soft real-time
  5. Anatomy of a real-time embedded system
  6. How real-time embedded software is structured
  7. Scheduling and multitasking
  8. Sharing data safely between tasks
  9. Programming real-time embedded systems
  10. Verifying timing
  11. Where real-time embedded systems are used
  12. Frequently asked questions

What is a real-time embedded system?

A real-time embedded system is a dedicated computer built into a larger device whose job is only done correctly if its outputs are logically right and produced on time. A brake controller that works out the perfect valve command 50 ms too late has failed, even though the arithmetic was flawless.

That is the core idea: in a real-time system, time is part of the specification. The system has to respond to events, like a sensor reading, a timer tick, or a packet arriving, within limits that are known in advance, and it has to do so every time. The limits that matter are not averages.

Two words carry the definition:

  • Embedded means the computer exists to serve a specific device or function, such as a washing machine, a motor drive, or an insulin pump. It is not a general-purpose machine that runs whatever software a user installs.
  • Real-time means the correctness of the system depends on when results appear, not just what they are.

If you want a shorter, definition-only answer, see what is meant by a real-time embedded system. This guide goes further: how the two properties relate, the timing vocabulary engineers use, how real-time software is structured, and how timing is checked.

Embedded system vs real-time system

People often use “embedded system” and “real-time system” as if they meant the same thing. They don’t. They describe two independent properties.

Embedded system Real-time system
Defined by Purpose and integration: a computer dedicated to one device or function Timing: results must arrive within specified time limits
Key question “What job does this computer do inside the product?” “By when must this result be ready?”
Typical constraints Cost, power, size, memory, reliability Deadlines, latency, jitter, worst-case behavior
Can exist without the other? Yes Yes

The four combinations

Treating the properties as separate gives four combinations:

  1. Embedded and real-time. An anti-lock braking controller, a motor drive, a drone flight controller, a pacemaker. These are dedicated computers with hard timing requirements, and they are what most people mean by “real-time embedded system”.
  2. Embedded but not meaningfully real-time. A digital photo frame or a simple calculator. Each is a dedicated device, but nothing bad happens if a response takes a little longer than usual.
  3. Real-time but not embedded. Some trading platforms, telecom switching servers, and flight simulators have strict timing requirements but run on general-purpose servers rather than inside a product.
  4. Neither. A desktop PC running office software.

In practice most embedded products contain some timing requirement. A thermostat still has to sample its sensor at a reasonable rate. That is why the line gets blurry. The useful question is not “is it real-time?” but “which parts have deadlines, how strict are they, and what happens if one is missed?”

Key timing concepts

Real-time engineering has its own vocabulary. You’ll see these terms throughout this cluster:

  • Deadline: the latest time by which a result must be produced. Usually given relative to when the triggering event occurs, for example “within 2 ms of the interrupt”.
  • Period: for work that repeats, how often it repeats. A control loop might run every 1 ms.
  • Latency / response time: how long it takes from an event to the system’s response. Interrupt latency is the delay before the first instruction of the interrupt handler runs. Response time usually means the full time until the work is done.
  • Jitter: variation in timing from one occurrence to the next. A loop that runs every 1.000 ms ± 0.002 ms has low jitter. One that runs anywhere between 0.8 and 1.3 ms has high jitter, which can hurt control quality even if no deadline is missed.
  • WCET (worst-case execution time): the longest a piece of code can take to run on the target hardware. Real-time analysis is built on worst cases, not typical cases.
  • Determinism / predictability: the property that the system’s timing can be bounded and reasoned about in advance.

A common misconception is that real-time means fast. It doesn’t. A system that must react within two seconds, every time, is real-time. A very fast system that is usually quick but occasionally stalls for an unpredictable period is not. Predictability matters more than raw speed.

Hard, firm, and soft real-time

Real-time requirements are usually grouped by what happens when a deadline is missed:

  • Hard real-time: a missed deadline counts as a system failure and may cause damage or harm. Airbag deployment and many flight-control functions are commonly given as examples.
  • Firm real-time: an occasional miss is tolerable, but a late result is worthless and is discarded. A dropped sample in some measurement or communication systems is an example.
  • Soft real-time: late results still have some value. Quality degrades, but the system keeps working. Audio or video playback that occasionally stutters fits here.

Most real products mix all three. A single car controller may have a hard deadline for actuating a valve, a firm deadline for processing a sensor message, and a soft deadline for updating a diagnostic display. Our article on hard vs soft real-time systems and timing constraints goes into the definitions, the edge cases, and how the classification changes your design.

Anatomy of a real-time embedded system

Most real-time embedded systems follow the same basic loop: sense → decide → act.

  • Sensors convert physical quantities, such as temperature, position, current, pressure, or acceleration, into electrical signals. These are often read through ADCs, digital interfaces like SPI or I2C, or timer capture inputs.
  • The processor, usually a microcontroller and sometimes a DSP, FPGA, or application processor, runs the control software.
  • Actuators turn decisions back into physical effects: motors, valves, heaters, relays, solenoids, displays, speakers.

Around that loop sit the hardware features that make real-time behavior possible:

  • Hardware timers generate precise periodic events and PWM signals.
  • Interrupts let the processor react to events immediately instead of polling for them.
  • DMA moves data between peripherals and memory without the CPU, which reduces latency and jitter.
  • Watchdog timers reset the system if software stops responding. This is an important safety net, but no substitute for correct timing.

How real-time embedded software is structured

Real-time doesn’t require any particular kind of software. There are several common architectures, and each can meet deadlines when it’s matched to the problem.

Super loop and foreground/background

The simplest structure is an endless while (1) loop in main() (the background) with interrupt service routines (the foreground) handling urgent events. ISRs capture data and set flags, and the main loop processes them. This approach is small, easy to reason about, and common in simple products. Timing is predictable as long as every pass through the loop is short and bounded.

Time-triggered and cooperative schedulers

A step up is a small scheduler that calls functions at fixed intervals from a timer tick. This is often called a cyclic executive or time-triggered design. Each task runs to completion and then returns. Because the timeline is fixed at design time, these systems can be very predictable, and they are used in some safety-related designs.

Real-time operating systems

An RTOS adds preemptive multitasking. Each task gets its own stack, and the kernel switches to the highest-priority ready task whenever something changes. This makes it much easier to write several independent activities, such as communications, control, logging, and a user interface, without them blocking each other. In exchange you take on more RAM use, more complexity, and new failure modes like race conditions and priority inversion. Our guide to when you actually need an RTOS vs a super loop walks through that decision. If you decide to try one, getting started with FreeRTOS is a practical first step, and FreeRTOS vs Zephyr vs ThreadX compares three popular options.

Real-time Linux and mixed-core designs

When a product needs a full operating system, with networking stacks, file systems, and a graphical UI, plus bounded latency, teams often use Linux with the PREEMPT_RT real-time capabilities, which were merged into the mainline kernel in 2024. Real-time Linux can deliver good latency for many applications, but it is generally harder to analyze than a small RTOS. Another common pattern is a heterogeneous processor: an application core runs Linux, and a separate microcontroller core runs an RTOS or bare-metal code for the hard real-time parts.

Scheduling and multitasking

Once more than one activity shares a processor, something has to decide what runs when. That’s the scheduler’s job. Embedded systems commonly use fixed-priority preemptive scheduling: every task has a priority, and the highest-priority ready task always runs. Priorities are often assigned by a principle called rate monotonic ordering (shorter period, higher priority), and there are mathematical tests to check whether a task set will meet all its deadlines.

Our article on real-time scheduling and multitasking in embedded systems covers these policies, the schedulability tests, and a worked example. If you’ve met scheduling in an operating systems course, the classic algorithms are covered in the four main types of scheduling algorithms and the four main processor scheduling policies.

Sharing data safely between tasks

Multitasking creates a new class of bugs. When two tasks, or a task and an interrupt, touch the same data, the result can depend on exactly when a context switch happens. RTOSes provide mutexes, semaphores, queues, event flags, and similar primitives to coordinate this. Using them correctly, and avoiding priority inversion and deadlock, is one of the core skills of real-time programming. See RTOS task synchronization and inter-task communication for the details.

Programming real-time embedded systems

Languages

  • C remains the dominant language for microcontroller firmware. It is close to the hardware, compilers exist for nearly every architecture, and vendor SDKs and RTOS kernels are mostly written in it.
  • C++ is widely used too, often a restricted subset that avoids features with unpredictable cost, such as exceptions and heavy dynamic allocation, in time-critical code.
  • Rust is growing in embedded work because of its memory-safety guarantees, with frameworks and RTOS options maturing.
  • Ada (and its SPARK subset) has a long history in aerospace and defense.

Safety-related projects often follow coding standards such as MISRA C or MISRA C++, which restrict language features that are error-prone or hard to analyze.

Habits that keep timing predictable

Whatever the language, real-time code tends to follow a few habits:

  • Bound every loop and every wait. A loop that polls a peripheral “until ready” should have a timeout.
  • Keep ISRs short. Capture data, clear the flag, signal a task, and return. Do the heavy processing elsewhere.
  • Avoid dynamic memory allocation after startup. malloc() can fragment the heap and has variable timing. Many projects allocate everything during initialization.
  • Be careful with blocking library calls. printf() over a slow UART, floating-point formatting, or flash writes can take far longer than expected.
  • Size stacks deliberately. In an RTOS, each task has its own stack, and overflows cause some of the hardest bugs to track down. See how to size RTOS task stacks and detect stack overflow.
  • Prefer static, predictable structures (fixed-size buffers, ring buffers, pre-allocated message pools) over growing data structures.

Verifying timing

Claims of real-time behavior should be measured, not assumed. Common techniques include:

  • GPIO toggling: set a pin high when a task or ISR starts and low when it ends, then watch it on an oscilloscope or logic analyzer. This is cheap and very effective for seeing latency and jitter directly.
  • Cycle counters: many cores have a hardware cycle counter (for example, the DWT cycle counter on many Arm Cortex-M3 and higher parts) that can time code paths precisely.
  • RTOS trace tools: tools such as SEGGER SystemView or Percepio Tracealyzer record task switches and interrupts so you can see what ran when.
  • Static WCET analysis: for the most critical systems, specialized tools analyze the compiled code to bound its worst-case execution time without relying on test inputs.
  • Stress testing: run the system at maximum load, with every interrupt source active, and watch for missed deadlines. Typical-case testing hides worst-case problems.

Where real-time embedded systems are used

Real-time embedded systems are everywhere timing affects safety, quality, or function: engine and brake controllers, flight computers, infusion pumps and ventilators, industrial robots and PLCs, motor drives and power inverters, audio interfaces, and radio basebands. For a tour organized by industry, with the kind of deadline each application faces, see real-time system applications and examples. For embedded systems more broadly, including the many everyday devices that aren’t strictly real-time, see real-life applications of embedded systems.

Frequently asked questions

Is every embedded system a real-time system?

No. Many embedded systems have loose timing requirements where a slow response is merely inconvenient. Most embedded systems have some timing expectations, but only those whose correctness depends on meeting specific time limits are properly called real-time.

Do real-time embedded systems need an RTOS?

No. Plenty of hard real-time systems run bare-metal code with interrupts and a carefully designed main loop or time-triggered scheduler. An RTOS helps most when you have several independent activities with different timing needs. It does not make a system real-time by itself.

What’s the difference between IoT and embedded systems?

IoT devices are generally embedded systems that are also connected to a network, usually to exchange data with cloud services or other devices. Every IoT device contains an embedded system, but many embedded systems, like a microwave oven controller or a car’s airbag module, are not connected to the internet.

Is embedded programming done in C or C++?

Both. C is the most common language for microcontroller firmware, and C++ is widely used, especially on larger projects and more capable processors. Rust is a growing third option. The choice usually depends on the toolchain, the vendor SDK, team experience, and any coding standards the project must follow.

Keep exploring

Guides from other topics

All topics →