Skip to content

Commit 7d1d833

Browse files
committed
fixes #13
1 parent 9a34fce commit 7d1d833

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

threads.tex

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ \section{Preemptive Multitasking}\label{threads-preemptive-section}
699699
currently executing instruction and the next one. Thus, rather than
700700
moving on to the program's next instruction, the processor jumps off
701701
to 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
703705
system, deals with the hardware device and then executes a \vocab{return
704706
from interrupt} instruction, which jumps back to the instruction that
705707
had been about to execute when the interrupt occurred. Of course, in
@@ -709,21 +711,31 @@ \section{Preemptive Multitasking}\label{threads-preemptive-section}
709711

710712
Using this interrupt mechanism, an operating system can provide
711713
preemptive 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
713717
accepting data from a network interface controller or updating the
714718
system's idea of the current time by one millisecond. Then,
715719
rather than simply restoring the registers and executing a return from
716720
interrupt instruction, the interrupt handler checks whether it would
717721
be a good time to preempt the current thread and switch to another.
722+
718723
For example, if the interrupt signaled the arrival of data for which a
719724
thread had long been waiting, it might make sense to switch to
720725
that thread. Or, if the interrupt was from the timer and the current
721726
thread had been executing for a long time, it may make sense to give
722727
another 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
724731
operating system decides to preempt the current thread, the interrupt
725732
handler switches threads using a
726733
mechanism 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

Comments
 (0)