Skip to main content

Thread, multithreading and necessity

Short answer

A thread is the smallest schedulable unit with own program counter, registers, and stack, sharing code and data within a process. Multithreading runs multiple threads concurrently, enabling responsiveness (blocked threads don't halt others), better CPU utilization, cheap communication via shared memory, faster creation/switching than processes, and parallelism on multi-core systems for real-time deadline handling.

Define thread in RTOS. Explain the concept of multi threading and why is it necessary.

A thread in an RTOS is the smallest unit of CPU scheduling: a single flow of control within a task/process, with its own program counter, registers and stack, sharing the code, data and resources of its parent task with other threads.

Multithreading

Multithreading means having several threads in one process, executing concurrently. On a single CPU the scheduler switches rapidly among them; on multiple cores they run in parallel.

 Process
  +--------------------------------------+
  | code, data, files (shared)           |
  |  Thread 1   Thread 2   Thread 3      |
  |  (own stack, registers, PC each)     |
  +--------------------------------------+

Example: an embedded data logger has one thread reading sensors, another updating the display, and a third sending data over UART.

Why it is necessary

  • Responsiveness: a blocked thread (waiting for I/O) does not stop the others, so the system stays responsive.
  • Better CPU utilisation: while one thread waits, another uses the CPU.
  • Resource sharing: threads share memory and data, so communication is easy and cheap.
  • Economy: creating and switching threads is faster and needs less memory than for processes.
  • Real-time handling of concurrent events: separate threads for different activities simplify the design and help meet deadlines.
  • Parallelism on multi-core processors improves performance.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 6 questions →