@@ -699,7 +699,9 @@ \section{Preemptive Multitasking}\label{threads-preemptive-section}
699699currently executing instruction and the next one. Thus, rather than
700700moving on to the program's next instruction, the processor jumps off
701701to the special procedure called the \vocab {interrupt
702- handler}. The interrupt handler, which is part of the operating
702+ handler}.
703+
704+ The interrupt handler, which is part of the operating
703705system, deals with the hardware device and then executes a \vocab {return
704706from interrupt} instruction, which jumps back to the instruction that
705707had been about to execute when the interrupt occurred. Of course, in
@@ -709,21 +711,31 @@ \section{Preemptive Multitasking}\label{threads-preemptive-section}
709711
710712Using this interrupt mechanism, an operating system can provide
711713preemptive multitasking. When an interrupt occurs, the interrupt
712- handler first takes care of the immediate needs, such as
714+ handler first
715+ saves the registers to the current thread's stack and
716+ takes care of the immediate needs, such as
713717accepting data from a network interface controller or updating the
714718system's idea of the current time by one millisecond. Then,
715719rather than simply restoring the registers and executing a return from
716720interrupt instruction, the interrupt handler checks whether it would
717721be a good time to preempt the current thread and switch to another.
722+
718723For example, if the interrupt signaled the arrival of data for which a
719724thread had long been waiting, it might make sense to switch to
720725that thread. Or, if the interrupt was from the timer and the current
721726thread had been executing for a long time, it may make sense to give
722727another thread a chance. These policy decisions are related to
723- scheduling, the topic of Chapter~\ref {scheduling-chapter }. In any case, if the
728+ scheduling, the topic of Chapter~\ref {scheduling-chapter }.
729+
730+ In any case, if the
724731operating system decides to preempt the current thread, the interrupt
725732handler switches threads using a
726733mechanism such as the \verb |switchFromTo | procedure.
734+ This switching of threads includes switching to the new thread's stack,
735+ so when the interrupt handler restores registers before returning,
736+ it will be restoring the new thread's registers. The previously running
737+ thread's register values will remain safely on its own stack until that
738+ thread is resumed.
727739
728740\section {Security and Threads }
729741
0 commit comments