The Complete Guide to Eclipse ThreadX and RTEMS
Learn Eclipse ThreadX and RTEMS side by side: history, thread and sync APIs, memory pools, builds, configuration and how to choose between them.

Two real-time operating systems have been running quietly inside products for decades while the public conversation circled around others. Eclipse ThreadX, born as a commercial kernel and now an open-source project of the Eclipse Foundation, sits in consumer devices, printers, modems and industrial controllers, usually bundled in a chip vendor's SDK. RTEMS, an open-source executive with roots in defense and space work, runs on spacecraft, instruments and networking equipment, and it ships with a broad set of standard interfaces. They look different and they solve the same problem: schedule threads by priority, let them share data safely and give the application bounded response times. This guide teaches both from the beginning, shows the same ideas in each so you can compare them, and ends with the decision of when to choose which. It uses ThreadX 6.4 and RTEMS 6 and refers to their own documentation: the Eclipse ThreadX project and the RTEMS documentation. Each topic has a deeper post in this cluster, linked in a later pass.
What a real-time kernel does
If you have not used one, the idea fits in a paragraph. A bare-metal program is one loop and some interrupt handlers. As it grows, the loop becomes a tangle of flags and timing assumptions. A real-time kernel replaces the loop with threads, each a function with its own stack and a priority. The kernel's scheduler always runs the highest-priority thread that is ready, preempting a lower one the moment a more urgent thread becomes ready. Threads wait on objects, a semaphore, a queue, a timer, and the kernel wakes them when the object is ready. Because the rules are fixed, you can reason about worst-case behavior: the highest-priority thread's response time depends on interrupt latency and on how long the kernel disables preemption, not on what the other threads are doing.
Everything in the rest of this guide is a variation on that theme: how threads are created, what objects they wait on, how memory is handed out and how the system is configured. If you hold the model, the API differences between ThreadX and RTEMS are vocabulary.
Where each came from
ThreadX was written by William Lamie and sold by Express Logic as a small commercial kernel, licensed to chip makers and device vendors. Microsoft bought the company in 2019 and renamed the kernel and its companions Azure RTOS. In late 2023 Microsoft donated the project to the Eclipse Foundation, which now hosts it as Eclipse ThreadX under the MIT license, with the code on GitHub under the eclipse-threadx organization. Companions come with it: NetX Duo for TCP/IP, FileX for FAT file systems, LevelX for flash wear leveling, USBX for USB and GUIX for graphics. You will see three names in documentation, Express Logic ThreadX, Azure RTOS ThreadX and Eclipse ThreadX, and they are one lineage with a mostly continuous API.
RTEMS began in the 1980s as a real-time executive for military systems and grew into a community project. It is open source, predominantly under a permissive BSD license, and developed in the open with its own toolchain build system and a long list of board support packages for Arm, PowerPC, SPARC, RISC-V, x86 and other architectures. It supports symmetric multiprocessing, several programming interfaces and, in its larger configurations, file systems and networking stacks derived from FreeBSD. It is a favorite where long service life, standards and a large body of verified code matter.
Two philosophies
The difference you notice first is the shape of the system. ThreadX is a compact kernel library with a uniform API. You link it into your firmware, write your own start-up and hardware code, and add companion stacks as needed. There is no board layer in the kernel: a port for a processor family provides the context switch and the timer interrupt, and the rest is yours or your vendor's.
RTEMS is a fuller executive. It ships with a board support package for each supported board that sets up the hardware, a clock driver, a console driver, a C library, and a set of managers for tasks, semaphores, message queues, timers, memory partitions, events and rate-monotonic scheduling, all in the native Classic API, with a POSIX layer beside it. You configure the application with macros that fix object counts at link time, build the kernel for a specific BSP and link your application against it. It feels closer to building against an operating system than to adding a library.
ThreadX: the program skeleton
Every ThreadX program has the same shape. main() prepares the hardware and calls tx_kernel_enter(), which starts the kernel and never returns. The kernel calls a function you write, tx_application_define(), once, before the scheduler starts, and there you create threads and objects:
int main(void)
{
/* clocks and pins */
tx_kernel_enter();
return 0;
}
void tx_application_define(void *first_unused_memory)
{
tx_thread_create(&worker, "worker", worker_entry, 0,
worker_stack, sizeof(worker_stack),
10, 10, TX_NO_TIME_SLICE, TX_AUTO_START);
}Nothing runs concurrently before tx_kernel_enter(), and nothing returns to main() after it. The ten arguments of tx_thread_create() are the control block, a name, the entry function, an integer passed to it, the stack address and size, the priority, the preemption threshold, the time slice and the start option. In ThreadX a lower priority number is more urgent, from 0 up to TX_MAX_PRIORITIES - 1, which defaults to 32 levels.
Two parameters need an explanation. The preemption threshold is a ThreadX feature: while a thread runs, only threads with a priority numerically below its threshold can preempt it. Setting the threshold equal to the priority gives ordinary behavior. A lower threshold shields the thread from a range of priorities and reduces context switches, and you can ignore it until you need it. The time slice is the number of ticks a thread may run before yielding to a ready thread of the same priority, and TX_NO_TIME_SLICE disables it.
Time is counted in ticks, set by TX_TIMER_TICKS_PER_SECOND, which defaults to 100. tx_thread_sleep(50) sleeps half a second at that rate. The tick comes from a hardware timer, SysTick on a Cortex-M part, whose interrupt handler must call the kernel's timer routine, and when you integrate ThreadX into a vendor HAL project, forgetting that hookup is the commonest reason sleeps never end.
Every ThreadX call returns a UINT status, with TX_SUCCESS for success. Check it while you learn: a failed tx_thread_create() leaves a thread that silently never runs.
RTEMS: the program skeleton
An RTEMS application starts from an initialization task called Init, not from main(). The kernel starts, initializes the BSP and drivers, and creates the task or tasks listed in a configuration table. Your code creates the rest:
rtems_task Init(rtems_task_argument argument)
{
rtems_id id;
rtems_task_create(rtems_build_name('W', 'K', 'R', '1'), 100,
RTEMS_MINIMUM_STACK_SIZE * 2,
RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &id);
rtems_task_start(id, Worker, 1);
rtems_task_delete(RTEMS_SELF);
}The function types are rtems_task, the names are four-character values built with rtems_build_name(), and the identifier returned in the last argument is what later calls use. Priorities run from 1 to 255, and as in ThreadX a lower number is more urgent. Creating and starting are separate calls so you can create many objects before any runs. Every call returns an rtems_status_code, with RTEMS_SUCCESSFUL for success, and rtems_status_text() turns a code into a string.
The configuration block at the bottom of the file is what surprises newcomers. Before including rtems/confdefs.h you define macros that state the application's needs: CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER, CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER, CONFIGURE_MAXIMUM_TASKS, CONFIGURE_RTEMS_INIT_TASKS_TABLE and, in exactly one file, CONFIGURE_INIT. RTEMS reserves its tables at link time from these numbers, so creation calls cannot fail later for lack of memory, and the memory map is a known quantity. If you forget the clock driver macro, rtems_task_wake_after() never returns. If the task limit is too small, creation fails with a too-many-objects status.
Priorities, preemption and the tick
Both kernels preempt by priority. In both, a thread that sleeps or waits gives the processor to the next ready thread, and a thread that becomes ready preempts a less urgent one at once. Both support round-robin among equal priorities through a time slice. The practical consequences are the same in each. A thread that never blocks and runs above others starves them. A shared variable written by two threads needs protection, because preemption can happen between any two instructions. Priorities should reflect deadlines, with more urgent work at lower numbers, and equal priorities should be used sparingly for threads that do continuous work.
Where they differ is in details around the scheduler. ThreadX offers the preemption threshold. RTEMS offers several scheduler implementations selected at configuration time, including a deterministic priority scheduler, a simple one for small systems and SMP variants, and it offers the rate-monotonic manager, a set of calls built for periodic work with deadline accounting. Both give you tick-based timeouts and, in recent versions, the option of a tickless idle on suitable ports.
Sharing data: queues, semaphores and events
Threads that never talk are rare, and both kernels give you the same three families of tool: something that carries data, something that carries only a signal, and something that carries a set of conditions.
In ThreadX, a message queue carries messages of a fixed size, counted in 32-bit words and chosen from TX_1_ULONG to TX_16_ULONG. You create it with tx_queue_create() over a block of memory, send with tx_queue_send() and receive with tx_queue_receive(). The queue copies messages by value, so the sender's buffer is free as soon as the send returns, and a sender blocks when the queue is full. A counting semaphore, tx_semaphore_create() with tx_semaphore_put() and tx_semaphore_get(), carries only a count, and put is safe from interrupt handlers. An event flags group, tx_event_flags_create() with tx_event_flags_set() and tx_event_flags_get(), is a 32-bit word of independent flags that a thread can wait on in an any or an all combination, with a clearing option that consumes them.
Every blocking ThreadX call takes a wait option as its last argument: TX_NO_WAIT, TX_WAIT_FOREVER or a tick count. A timeout is a normal result, reported with a status such as TX_QUEUE_EMPTY or TX_NO_EVENTS, and the code should decide what to do about it.
RTEMS has the same three families as managers. The message queue manager has rtems_message_queue_create(), rtems_message_queue_send() and rtems_message_queue_receive(), with the message size fixed at creation and the buffer memory reserved by a configuration macro. The semaphore manager has rtems_semaphore_create(), rtems_semaphore_obtain() and rtems_semaphore_release(), where creation attributes choose between a counting semaphore, a binary semaphore and a mutex-like semaphore with priority inheritance or a priority ceiling. The event manager has rtems_event_send() and rtems_event_receive(), in which each task has its own set of events that others can send to it, which is a slightly different model from ThreadX's shared flags group.
A table helps keep the two straight:
| Need | ThreadX | RTEMS Classic API |
|---|---|---|
| Carry data | tx_queue_* | rtems_message_queue_* |
| Count signals | tx_semaphore_* | rtems_semaphore_* (counting) |
| Wait on several conditions | tx_event_flags_* | rtems_event_* |
| Protect shared data | tx_mutex_* with TX_INHERIT | rtems_semaphore_* with inheritance |
| Periodic work | tx_timer_* and sleeps | rate monotonic manager |
Mutual exclusion and priority inversion
When two threads share a variable or a device, one must be kept out while the other works. A semaphore can do the job and has a flaw that bites real systems: priority inversion. A low-priority thread holds the lock, a high-priority thread waits for it, and a medium-priority thread that does not need the lock preempts the holder, so the high-priority thread is blocked for as long as the medium one runs. Both kernels offer the cure, a mutex with priority inheritance, which temporarily raises the holder's priority to that of the highest waiter.
In ThreadX you create it with tx_mutex_create(&lock, "lock", TX_INHERIT), take it with tx_mutex_get() and release it with tx_mutex_put(); a thread that already owns the mutex can take it again, and the kernel counts the nesting. In RTEMS you create a semaphore with attributes that select a binary semaphore with inheritance, or a priority ceiling for the other well-known protocol, and use rtems_semaphore_obtain() and rtems_semaphore_release(). In both, keep the protected section short, never block inside it and never take two locks in different orders in different threads, which is how deadlocks are born.
Interrupt handlers cannot take a mutex, because they cannot block. The standard pattern is for the handler to record the event and signal a thread through a semaphore, an event or a queue send with no wait, and for the thread to do the protected work.
Memory: pools, not heaps
Embedded systems have two quarrels with a general heap: its timing is unpredictable and it fragments. Both kernels give you pools instead.
ThreadX offers two kinds. A byte pool hands out variable-sized pieces from a region with a first-fit search, tx_byte_pool_create(), tx_byte_allocate() and tx_byte_release(). Each allocation carries a small header, so a pool holds fewer pieces than raw arithmetic suggests, and a long mix of sizes can fragment it. A block pool hands out fixed-size blocks, tx_block_pool_create(), tx_block_allocate() and tx_block_release(), in constant time with no fragmentation, and each block needs its size plus one pointer in the region. Both let a thread wait for memory with a timeout, and block-pool allocation with no wait is the right tool inside an interrupt. The sound pattern is to allocate stacks and long-lived objects from a byte pool at start-up and to run the hot paths on block pools sized per object type.
RTEMS has the partition manager for fixed-size buffers, with rtems_partition_create(), rtems_partition_get_buffer() and rtems_partition_return_buffer(), which behaves like a block pool, and the region manager for variable-size segments from a memory region, rtems_region_create() and rtems_region_get_segment(), which behaves like a byte pool. RTEMS also provides a standard C library malloc() backed by a heap whose size you configure, and most RTEMS programs use it for non-critical allocation. Whichever you use, the rule is the same: allocate at start-up when you can, prefer fixed-size blocks for anything that flows between threads and watch free memory in a long soak test, since a leak or fragmentation takes days to show.
Timers and periodic work
Much real-time work is periodic: read a sensor every ten milliseconds, send a heartbeat every second. The cheap way is a loop that sleeps, tx_thread_sleep() or rtems_task_wake_after(), but a sleep measured from the end of the work drifts: if the work takes 2 ms and you sleep 10, the period is 12. Both kernels have a better tool.
ThreadX application timers call a function at a set time or repeatedly: tx_timer_create(&timer, "tick", expiry_fn, input, 10, 10, TX_AUTO_ACTIVATE) calls the function after 10 ticks and every 10 ticks after. The function runs in the context of the system timer thread, so it must be short and must not block. For longer work, have the expiry function release a semaphore that a worker thread waits on.
RTEMS has the rate monotonic manager, built for this. A task creates a period object with rtems_rate_monotonic_create() and then calls rtems_rate_monotonic_period(id, ticks) at the top of its loop. The first call starts the period, and later calls block until the period expires, returning a status that tells you whether the previous period overran. That gives you a drift-free periodic loop with deadline detection in one call, and statistics through rtems_rate_monotonic_get_statistics() on how long each period actually took. The name refers to rate monotonic analysis, the scheduling theory that assigns higher priority to shorter periods, which the manager supports directly.
Interrupts
An interrupt handler in either system is a plain C function installed for an interrupt line, with the usual rules: keep it short, never block, never call a function that may wait. The kernel's job is to make it safe to signal a thread from a handler. ThreadX services such as tx_semaphore_put(), tx_queue_send() with TX_NO_WAIT and tx_event_flags_set() are safe from interrupts, and on most ports the vector for the tick is already wired to the kernel. RTEMS provides rtems_interrupt_catch() and the newer interrupt server and handler installation calls, and its manager services document which are callable from an ISR.
The pattern that works is the same everywhere. The handler acknowledges the hardware, grabs the data into a buffer, signals a thread and returns. The thread does the real work at its own priority. Priorities then express importance: a thread that handles a critical interrupt's data runs above a thread that logs.
Error handling and stack discipline
Both kernels leave stack sizing to you, and an overflow in a flat memory model corrupts a neighbor silently. In ThreadX each thread's control block records the lowest stack address reached, tx_thread_stack_highest_ptr, and a build option fills stacks with a pattern so the high-water mark is exact; the tx_thread_info_get() call reads the fields at run time. RTEMS keeps a stack checker you enable at configuration with CONFIGURE_STACK_CHECKER_ENABLED, which fills each stack with a pattern, checks the guard at every context switch and reports an overflow with the task name. Use whichever your kernel provides in every development build, run the worst case and size each stack at the measured use plus a margin.
Check return codes everywhere while learning, and decide what each failure means. A timeout on a queue is normal. A failed create is a design error, since the object tables or memory were not sized for what you asked. In RTEMS, a status other than RTEMS_SUCCESSFUL from a directive can be turned into a fatal error with a short macro of your own, so mistakes stop the system at the line that made them instead of showing up later.
Getting ThreadX onto a chip
ThreadX's source tree has a common directory with the portable kernel and a ports directory with one subdirectory per processor family and toolchain, for example ports/cortex_m4/gnu. A port supplies the few pieces that depend on the processor: the context switch, the interrupt entry and exit code, the stack setup for a new thread and the low-level start-up. You add the common sources and one port to your project, define the configuration in tx_user.h or through compiler definitions, and provide two things yourself.
The first is the system tick. ThreadX needs a periodic interrupt, and on a Cortex-M part that is SysTick. The port's start-up code includes a handler that calls the kernel's timer routine, and you must configure SysTick to the tick rate you want from the core clock. When you build inside a vendor HAL project, the HAL also wants SysTick for its own HAL_GetTick(), and the two must be reconciled, usually by letting the ThreadX handler call the HAL's increment function as well, or by moving the HAL's time base to another timer. A system whose tx_thread_sleep() never wakes almost always has this wrong.
The second is memory for the kernel's first use. tx_kernel_enter() calls a low-level initialization routine that passes your application the address of the first unused RAM, derived from a linker symbol, and you may use it to create the first byte pool. Getting that symbol wrong, or placing the pool over memory that something else owns, corrupts the system at boot, and the symptom is a crash before your first thread runs. Check the port's initialization source and your linker script together.
Vendor SDKs make most of this invisible. STMicroelectronics' STM32Cube packages include ThreadX with the glue written, and the same is true for several other vendors. If you start from such a package you modify the application, not the port. If you start from the upstream repository, copy the sample project for the nearest port and adjust it.
Getting RTEMS onto a board
RTEMS has a longer front door and a shorter hall. You first build a toolchain for the architecture with the RTEMS Source Builder: clone it, check the host with sb-check, and run sb-set-builder --prefix=$HOME/quick-start/rtems/6 6/rtems-sparc for the SPARC set, or the set for your architecture. This takes a while because it builds binutils, GCC, a C library and GDB from source for the target triple, sparc-rtems6 in this example. Then you clone the RTEMS source, choose a BSP named architecture/board, such as sparc/erc32, which runs on a simulator, or a real board's BSP, and generate the configuration file with Waf:
./waf bsp_defaults --rtems-bsps=sparc/erc32 > config.ini
./waf configure --prefix=$HOME/quick-start/rtems/6
./waf
./waf installThe result is the kernel and BSP libraries installed under the prefix, ready for applications to link against. An application compiles with the cross compiler, naming the BSP's library directory and the RTEMS specs, and produces an ELF that you run on the simulator, sparc-rtems6-sis, or flash to a board by whatever procedure the board's documentation gives. Keep config.ini under version control, since it is the record of how your kernel was built, and keep each RTEMS release under its own prefix.
The BSP is the most important choice. It decides the processor, the memory map, the console and clock drivers and the options for that board. Check that a BSP exists for your hardware before you plan around RTEMS. If it does not, porting one is a project, though far from starting from nothing, since RTEMS has many BSPs to copy from.
The ecosystem around each
ThreadX's companions are designed as a family. NetX Duo provides TCP/IP with IPv4 and IPv6, sockets, TLS support and clients and servers for common protocols, and it runs on the ThreadX kernel's objects. FileX gives a FAT file system, and LevelX adds wear leveling for NOR and NAND flash. USBX provides USB host and device classes, and GUIX a toolkit for displays. They share an API style and a quality bar, which lowers the cost of adding a feature. Because the kernel has no board layer, hardware drivers come from the chip vendor's HAL, and the common pattern is ThreadX plus the vendor HAL plus the companions you need.
RTEMS ships a larger platform. Its C library provides the POSIX interfaces, and a POSIX API layer beside the Classic API lets you write portable threaded code. It includes several file systems, the in-memory IMFS, FAT, and others, and networking either through a FreeBSD-derived stack in the rtems-libbsd package or through lwIP. Drivers for each BSP's peripherals live in the tree, and RTEMS supports symmetric multiprocessing on suitable processors, with scheduling that is aware of cores. The project has a long record of use in systems that run for decades, and its documentation and test suite are extensive.
Watching the system run
Both systems have tools for seeing what threads are doing, and you should use them from the first day. ThreadX has a trace facility, TraceX, a host tool that reads an event buffer the kernel fills when you enable tracing, and displays a timeline of thread switches, interrupts and kernel calls. The control blocks also expose fields a debugger can read, such as a thread's state, its priority and its stack bounds. You can read a thread's information in code with tx_thread_info_get() and a pool's with tx_byte_pool_info_get().
RTEMS can print reports of its own state. The CPU usage report, rtems_cpu_usage_report(), lists how much processor time each task has consumed, and rtems_stack_checker_report_usage() prints the stack use of every task, both callable from your code or a shell if you configure one. The rate monotonic statistics tell you how long each periodic task's cycles really took. RTEMS also integrates with GDB and, on many BSPs, offers a trace facility for post-mortem analysis. Whichever kernel you use, a debug build that prints thread states and stack use on a key press or a command is worth the half hour it takes to write.
Configuration is a design document
Both systems turn the application's needs into numbers, and it pays to treat those numbers as a design document rather than as boilerplate. In ThreadX, the maximum number of priorities, the tick rate, whether the preemption threshold is compiled in and whether the stack checks and the trace buffer are enabled are compile-time choices in tx_user.h that change code size and behavior. Writing down why each is set the way it is makes the next port, and the next engineer, faster. In RTEMS the equivalent is the block of CONFIGURE_ macros, where each line is a promise about the system: the number of tasks, semaphores, message queues and timers, the size of the message buffer memory, the stack space for the initialization task, the clock tick length in microseconds. Because those counts reserve memory at link time, a memory report from the link is a bill of materials for the operating system, and a change that adds a task shows up as a visible change in the report.
The discipline that works is to review these numbers whenever the design changes. When a developer adds a thread, they also adjust the counts, the stack budget and the priority table, and the review checks that the new thread's priority fits the deadline analysis. Keep the priority table in one place, a header with named constants, because the relative order of priorities is a system property and scattering magic numbers through the sources hides it. A table that lists each thread, its priority, its period or trigger, its stack size and the objects it uses is a page of documentation that answers most questions a new maintainer will ask.
Testing
Both lend themselves to testing on a host. RTEMS builds for simulators, SIS for SPARC and QEMU for several architectures, and its own large test suite runs there in the project's continuous integration, which is also the best collection of examples of how to call each directive. ThreadX has ports for Linux and Windows hosts, where the kernel runs as a process with the scheduler built on host threads, so application logic that depends only on ThreadX objects can be built and exercised with host tools. Neither replaces testing on the target, because timing, interrupts and hardware behavior differ. Use the host for logic and the board for timing.
Comparing them directly
| Question | Eclipse ThreadX | RTEMS |
|---|---|---|
| Shape | Small kernel library with companion stacks | Full executive with BSPs and managers |
| License | MIT | Predominantly BSD-2-Clause |
| Native API | tx_* functions, TX_SUCCESS | Classic API managers, RTEMS_SUCCESSFUL |
| POSIX | Not the main interface | Strong POSIX layer |
| Hardware support | Via vendor HALs and ports | Via BSPs in the tree |
| Configuration | Compile-time defines, tx_user.h | CONFIGURE_ macros fixing object counts |
| SMP | Available in some ports, check the documentation | Mature SMP support |
| Typical home | Vendor SDKs, consumer and industrial devices | Space, defense, instruments, networking |
| Build front door | Add sources to your project | Source Builder toolchain, Waf kernel build |
The table shows structure, not measured performance. For image size, RAM use and latency, build the same small program on both for your chip and measure.
Choosing between them
Choose ThreadX when you want a compact kernel you drop into an existing firmware project, when your chip vendor already ships it with working ports and examples, or when you want the companion stacks for networking, files and USB from one family. It fits a product team that wants an RTOS as a library and keeps control of its own hardware layer.
Choose RTEMS when your target has a mature BSP, when you want a broad standard platform, POSIX interfaces, SMP and file systems and networking, or when your field is one where RTEMS has a long track record and documentation to match. It fits a team that treats the operating system as a platform to build against and values determinism fixed at link time.
Choose neither if the application is a state machine on a tiny part, where a super-loop is simpler, or if you need a large vendor-supported driver collection and a declarative hardware description, where Zephyr may serve you better. If your team already knows one system well, retraining is a real cost.
Licensing, safety and support deserve a separate look. Both are permissively licensed, so commercial use is allowed with notices kept. Neither guarantees certification: ThreadX has a history of safety certification for earlier versions, and RTEMS has been used in qualified systems, but whether a certificate applies to the version you build is a question for the project and the certification body. Commercial support exists for both from third parties.
Mistakes that cost the most time
ThreadX: forgetting to wire SysTick to the kernel's timer routine, so sleeps never end.
ThreadX: a stack too small for the context saved on preemption, especially with floating point.
ThreadX: returning from a thread entry function, which ends that thread.
RTEMS: omitting the clock driver macro, so
rtems_task_wake_after()never returns.RTEMS: setting
CONFIGURE_MAXIMUM_TASKStoo low, then ignoring the status code.RTEMS: defining
CONFIGURE_INITin more than one file.Both: using a semaphore for mutual exclusion and meeting priority inversion.
Both: ignoring return codes while learning.
Both: sizing stacks from the average instead of the worst case.
A learning path
Start with threads: create two that sleep and print, and watch the priorities decide the order. Add a message queue between them. Add a semaphore signaled from a timer or an interrupt. Replace a polling loop with a periodic structure, an application timer or a rate monotonic period. Add a mutex with priority inheritance around a shared buffer and write the inversion scenario on purpose to see why it matters. Measure stack use and size each stack from evidence. Then add one companion: NetX Duo or FileX for ThreadX, a file system or network stack for RTEMS. Do the exercise on both kernels if you can, since the second teaches you what is the idea and what is the vocabulary.


