Use an RTOS to coordinate embedded work through explicit task responsibilities, event waits and data ownership. A good design says which context produces data, which consumes it, how long each may wait and what happens under overload. Creating many tasks without those contracts usually makes failures harder to reproduce.
Reviewed 12 November 2026 · Worked examples with stated assumptions
On this page
Design a three-stage pipeline
For a teaching sensor node, acquisition produces timestamped records, processing validates and transforms them, and reporting sends results. A separate supervisor observes progress. Assign each record an owner and define how ownership moves through a queue.
Do not pass a pointer to a stack object that disappears before a consumer reads it. Copy small records or use a pool with explicit lifetime rules.
Block for events instead of polling continuously
A task can wait for data, a notification or a time event rather than repeatedly reading a flag. This lets other ready work execute. Choose finite timeouts where a missing event must trigger recovery.
An ISR should use the kernel APIs permitted for interrupt context and follow the port’s priority restrictions. A normal task API is not automatically safe inside an ISR.
Bound queue capacity and overflow
If records arrive once per millisecond and the consumer can stop for 8 ms, consider accumulated records, boundary phase, existing occupancy and any burst behavior. Document whether a full queue drops the newest record, discards old data or raises a fault.
Test that policy explicitly. A full-queue test is more informative than a long run where the consumer is always faster than the producer.
Protect shared resources deliberately
A mutex can express task ownership of a shared resource and may offer priority inheritance. It is generally unsuitable as an ISR-owned lock. Avoid holding a mutex across unbounded external I/O, and establish an order when multiple resources are needed.
For shared data, choose queues, atomics or short protected operations according to the platform and requirement. Adding volatile is not a substitute for a synchronization design.
Build an observable validation plan
- Timestamp acquisition and completion to measure response time.
- Record queue high-water marks and losses.
- Check each task’s stack under demanding call paths.
- Inject delayed input, stalled consumers and unavailable resources.
- Verify startup, timeout and recovery behavior.
The response-time worksheet uses an idealized fixed-priority model. Target measurements and a complete workload model remain necessary before making deadline claims.
Common questions
Should an ISR wait for a mutex?
Do not design an ISR to block on a task-owned mutex. Use the interrupt-safe communication mechanisms supported by the kernel and port.
Can a queue solve every concurrency problem?
No. It helps define transfer and waiting, but capacity, lifetime, timing and failure policies still need design.
References and practice checks
The practice package includes original arithmetic models, a small RTL simulation and a host C exercise. Each states its test boundary; none is a silicon or board validation claim.