The Embedded Frontier podcast

#029 - How to Write Fast RTOS Code

0:00
34:39
Rewind 15 seconds
Fast Forward 15 seconds
Jacob Beningo talks with RTOS pioneer Bill Lamie, creator of Nucleus, ThreadX, and PX5 RTOS, about how to write efficient, high-performance real-time code. They cover POSIX pthreads, keeping software simple, RTOS benchmarking, test-driven development, using AI as a development teammate, and practical tips for structuring RTOS applications.

Key Takeaways:

• Keep it simple: complexity is the biggest enemy of embedded software, and a complex solution is probably not the right one.
• Minimize nested function calls in critical paths, since pushing and popping registers and return addresses is expensive.
• Design for performance from the start. Every comparison and data reference matters in the real-time path, and performance can't be bolted on at the end.
• Use an error-checking veneer selectively. Enable it for new or untrusted code and call the direct API for proven code to save cycles.
• Standardizing on the POSIX pthreads API makes it easier to share code between Linux and RTOS-based products and to move between RTOSes.
• Write documentation before code to keep your design flexible and expose interfaces that are hard to explain.
• Adopt test-driven development by writing test cases before the code. This keeps you from writing unreachable paths and makes coverage targets such as 100% statement and branch coverage achievable.
• Treat AI as a teammate, not a replacement. It excels at tedious tasks like proofreading, QA, concurrency review, and quick hardware lookups, but it isn't reliable for pure code generation.
• Put as many threads as possible at the same priority and use higher priorities only when preemption is absolutely necessary.
• Use a minimalist number of threads and system objects to reduce accidental RTOS overhead.

Links:

• PX5 RTOS
• Bill Lamie on LinkedIn
• 2026 RTOS Performance Report
• Eclipse ThreadX
• Why RTOS Functional Safety Certification Matters
• RTOS Best Practices Course

More episodes from "The Embedded Frontier"