The Myth: The operating system is in charge and it decides when to switch from one application task to another.
The Truth: A real-time operating system (RTOS) is a very different beast than a multi-user desktop operating system, such as Linux. In fact, an RTOS is simply a library of functions plus a timer tick interrupt handler.
The only opportunities for an RTOS to effect a context switch from one task to another are:
1. If a running task deletes itself (or exits, if your OS allows that). In this case, a function in the RTOS library detects the lack of a running task and can directly invoke the scheduler function to select the next task to run.
2. When a running task blocks, which can only happen by making a function call into the RTOS library.
3. If a running task creates a new task with a priority higher than it’s own.
4. When a previously blocked task of higher priority is unblocked, which could happen as a result of:
a. The running task made a function call into the RTOS library (e.g., semaphore post).
b. An interrupt service routine executed with that side effect.
These four (or, five, if you prefer) points of entry into the RTOS are the only mechanisms by which control of the CPU can be transferred from one task to another. They are called “scheduling points”.
The implication here is that your application code is actually in charge. If it were to avoid calling into the RTOS library while simultaneously disabling interrupts, the running task could steal control of the CPU for any length of time.