Topics / RTOS & Real-Time Systems / Q30
What are common RTOS design mistakes?
Short answer: The usual mistakes are: too many tasks; busy-waiting instead of blocking; blocking or slow calls in ISRs; wrong interrupt priorities relative to the kernel's syscall priority; holding mutexes during slow I/O or taking them in inconsistent orders; sharing globals without protection; undersized stacks; ignoring API return values and timeouts; and creating/deleting tasks and objects at run time.
| Mistake | Consequence | Better approach |
|---|---|---|
| A task per small job | wasted stacks, more switches and sharing | group related work; use event-driven tasks |
Polling loops (while (!flag);) |
starves lower priorities, burns power | block on notifications/queues |
printf, malloc, blocking APIs in ISRs |
crashes, deadlocks, latency | defer to tasks; use FromISR APIs |
ISR priority above configMAX_SYSCALL_INTERRUPT_PRIORITY calling the API |
rare random corruption | follow the priority rule; enable configASSERT |
| Holding a mutex during flash writes or network calls | priority inversion, latency for others | copy data, release, then do slow work; single-owner tasks |
| Inconsistent lock order | deadlock | global lock ordering; message passing |
| Unprotected shared globals | race conditions | mutex, critical section, or atomics |
| Stack sizes guessed once | random crashes later | measure high-water marks, overflow checks |
portMAX_DELAY everywhere |
silent hangs | finite timeouts and error handling |
Ignoring return values (xQueueSend failed) |
lost data | check and count failures |
| Dynamic creation/deletion at run time | fragmentation, leaks | create at init; static allocation |
Using vTaskDelay for periodic loops |
drift | vTaskDelayUntil or timer-driven tasks |
| Not watching CPU load / idle time | unnoticed overload | run-time stats, trace, watchdog supervision |
Interview tip: pick two or three from your own experience and describe how you found them (trace tools, high-water marks, configASSERT) — that is more convincing than reciting the list.