Context switching saves the execution state of one task and restores the state of another. In a robot, this lets a scheduler pause a running task and resume a different task. section 3.5
Preemption triggers a switch when a higher-priority task must run, such as a periodic control task interrupting a lower-priority task. The switch is not free: frequent switching adds overhead and latency, which can threaten real-time deadlines. section 3.5
Two robot tasks
Suppose task A controls a time-critical robot function while task B performs less urgent work. The scheduler assigns A higher priority, pauses B when A is ready, restores A's saved state, and later resumes B. Timers can regularly invoke the scheduler to make this decision. section 3.5
Figure 3.14 Preemptive scheduling ensures temporal correctness by allowing a higher-priority real-time task to pause and temporarily replace a running lower-priority task, ensuring both tasks meet their execution deadlines.
Use the scheduling diagram to connect preemption, priority, task replacement, and temporal correctness. section 3.5









