Lesson 5.15 · Answer it
Tasks on hold
5 marksYou mark it yourself against the marking points
Sam works on a help desk. While Sam is working on a task, a more urgent task can arrive. Sam then puts the task in hand on hold and starts the new one, and that new task can be interrupted in the same way. When Sam finishes a task, Sam goes back to the task that was put on hold most recently. The tasks on hold are kept in a stack.
(a) Sam is working on task A. Task B arrives and interrupts A; later, while Sam works on B, task C arrives. State the tasks on hold now, bottom first. [1]
(b) Sam then finishes task C. State the task Sam goes back to, and name the stack operation used, so that the stack again holds only the tasks on hold. [2]
(c) Suppose the tasks on hold were kept in a queue instead, joining at the back and leaving from the front. Using tasks A, B and C, explain why the queue would give Sam the wrong task when C is finished. [2]
[5]