Skip to content
Tech Interview Prep
Technical interview guide

RTOS & Task Scheduling

How a real-time operating system schedules multiple tasks with timing guarantees, and the classic concurrency hazards (priority inversion, deadlock) that come with it.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: CMSIS-RTOS2 current API; CMSIS-RTX5 current configuration; current FreeRTOS and Zephyr scheduling guidance reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

RTOS & Task Scheduling

In one line

A real-time operating system runs tasks under a documented scheduling policy so that every task's worst-case response time is bounded and met. Reach for fixed-priority preemptive scheduling with blocking primitives when several tasks have deadlines and share resources.

Key definitions

  • Hard, firm, soft deadline: a hard miss is a system failure, a firm miss yields a result of no value, a soft miss lowers quality.
  • Reschedule point: a tick, a block, an unblock, or an ISR that requests a yield. The scheduler picks the highest-priority ready task there.
  • WCET: worst-case execution time. The mean does not bound a deadline.
  • Blocking term B: the longest time a task waits on a resource held by a lower-priority task.
  • Priority inheritance: the mutex owner runs at the highest priority of any waiter while it holds the mutex.
  • Priority ceiling: each mutex carries the highest priority of any task that may lock it.

Formulas and complexity

Response-time analysis for fixed-priority preemptive tasks, where hp(i) is the set of higher-priority tasks. Start at R = C_i + B_i and iterate until it converges. If it passes the deadline, the task is unschedulable.

Ri(n+1)=Ci+Bi+∑j∈hp(i)⌈Ri(n)Tj⌉CjR_i^{(n+1)} = C_i + B_i + \sum_{j \in hp(i)} \left\lceil \frac{R_i^{(n)}}{T_j} \right\rceil C_j

Add interrupt interference as a term in the same sum.

Utilization:

U=∑iCiTiU = \sum_i \frac{C_i}{T_i}

Utilization is scheduling slack. It is not a schedulability verdict: a set at 0.69 can still miss a deadline once a blocking term is added.

How it works

  • A task runs until it blocks, is preempted by a ready higher-priority task, or finishes.
  • Blocking removes the task from the ready list and places it on the object's wait list. An unblock returns it.
  • At each reschedule point the highest-priority ready task runs. Equal priorities may time-slice.
  • An ISR that wakes a task must use the FromISR API and request a yield. Otherwise the woken task waits for the next tick, which is 1 ms on a 1 kHz tick.
blocks on queue, mutex or delay event or timeout highest priority at reschedule point ISR or tick makes higher-priority task ready Running Blocked Ready

When to use and when not to

SituationChooseWhy
Mixed priorities, deadlines, shared resourcesPreemptive fixed-priority plus RTABounded response time, if WCET and blocking are bounded
Short run-to-completion segments, no hard deadlineCooperativeSimpler. One long segment starves every other task
Single loop, no blocking, deadlines trivially metNo RTOSOverhead and failure modes with no benefit
Timing met by a hardware timer or DMAHardwareNo scheduler needed for the timed action
WCET or blocking cannot be boundedDo not claim hard real-timeNo analysis, no bound

Traps interviewers probe

  1. Priority by importance. Assign by deadline or response urgency. Under rate-monotonic assignment the shorter period gets the higher priority. Document release rate, deadline, WCET, blocking and interference for each critical task.
  2. A semaphore used as a lock. A binary semaphore has no owner and no inheritance, so the wrong task can release it and a waiter cannot boost the holder. Use a mutex for exclusive resources (Mars Pathfinder was fixed by enabling inheritance on its mutex). Use semaphores for counts and events.
  3. Utilization as the verdict. A low CPU share says nothing about blocking. Fix: add B and interrupt time to the RTA and measure the blocking chain.
  4. Circular lock order. Four tasks taking the same pair of locks in different orders deadlock under load. Fix: one global lock order, bounded acquisition with diagnosis, and no blocking calls while holding a lock.
  5. Lost wakeups and coalesced flags. Testing a condition outside the mutex, then waiting, loses the signal. Fix: test the condition under the mutex in a loop before waiting. Thread flags coalesce: five sets of one bit wake the thread once, so drain the whole FIFO on each wakeup.

Interview tips

Open with: real-time means bounded worst-case response time under a declared workload. Fast is not the claim.

Expect these follow-ups:

  • What makes it hard? Release pattern, priorities, WCET, blocking, interrupts, kernel configuration, resource capacity.
  • How does priority inversion arise, and how do inheritance and ceiling differ? Inheritance boosts the owner. The ceiling blocks entry unless priority exceeds the system ceiling. Both leave residual blocking in the RTA.
  • How do you prevent deadlock? Break a Coffman condition, most practically circular wait through lock ordering.
  • How does an ISR hand off to a task? FromISR API, permitted interrupt priority, yield if a higher-priority task woke.
  • What is your overload policy? Bounded admission, shedding, degradation or safe state, with drops counted.

30-second answer outline:

  1. Define the goal: bounded worst-case response for every task under the declared load.
  2. Mechanism: fixed-priority preemption at reschedule points, with tasks blocking on queues and mutexes.
  3. Hazard: priority inversion on a mutex. Fix with priority inheritance, then carry the residual blocking into the analysis.
  4. Evidence: WCET measured on the release build, RTA including B and interrupts, and a missed-deadline counter on the release image.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.