What kinds of threads run in an RTOS application, and how do ISRs, tasks and the idle task differ?
An ISR is started by a hardware interrupt and runs to completion on a shared stack; a task is a long-living thread with its own stack that can block while waiting for an event; the idle task has the lowest priority and runs only when nothing else is ready.
A thread is the basic unit of execution in an RTOS application. There are three kinds:
| Thread type | Started by | Lifetime | Stack | Can it block? |
|---|---|---|---|---|
| Interrupt Service Routine (ISR) | A hardware interrupt | Runs to completion, then returns | ISRs share one stack | No |
| Task | The scheduler | Long-living, usually an endless loop | Each task has its own stack | Yes, waiting for events |
| Idle | The scheduler, when nothing else is ready | Always present | Its own | Never; it is the fallback |
The own-stack point explains the rest. A task can stop halfway through, have its registers saved, and resume later because its stack holds its state. An ISR cannot, which is why good practice is to keep ISRs very short: read the hardware, give a semaphore or send to a queue, and let a task do the real work.
The idle task is where the system saves power. In FreeRTOS it also cleans up deleted tasks, and a hook function can put the processor to sleep there.
Go deeper:
Wikipedia — Interrupt handler — why ISRs must be short, and the split into a fast first-level and a deferred second-level handler.