Information Technology Reference
In-Depth Information
The idle thread.
If a system has k processors, then there will normally be exactly k R UNNING threads;
the operating system typically keeps a low priority idle thread per processor and runs it
if there is nothing else to run.
In old machines, the idle thread would spin in a tight loop doing nothing.
Today, to save power, the idle thread is typically a loop that on each iteration puts the
processor into a low-power sleep mode in which the processor stops executing instruc-
tions until a hardware interrupt occurs. Then, when a hardware interrupt occurs, the
processor wakes up and handles it in the normal way—saving the state of the currently
running thread (the idle thread) and running the handler. After running the handler,
if a thread other than the idle thread is R EADY , the scheduler runs that thread next;
otherwise, the idle thread resumes execution, putting the processor to sleep again.
a a thread to transition from theReadytoRunningby copying the thread's
register values from its TCB to a processor's registers.
Running. A thread in theRunningstate is running on a processor. When a
thread isRunning, its register values are stored on a processor rather than in
the TCB data structure. ARunningthread can transition to theReadystate
in two ways.
The scheduler can preempt a running thread and move it to theReady
state at any time by saving the thread's registers to its TCB and switching
the processor to running the next thread on the ready list.
A running thread can voluntarily relinquish the processor go fromRun-
ningtoReadyby calling yield() (e.g., sthreadyield() in the sthreads
library.)
Notice that a thread can transition betweenReadyandRunningand back
many times while it runs. Since the operating system saves and restores the
thread's registers exactly, only the speed of the the thread's execution is aected
by these transitions.
Waiting. A thread in theWaitingstate is waiting for some event. Whereas
a thread in theReadystage is eligible to be moved theRunningstate by the
scheduler, a thread in theWaitingstate is not eligible to be run until some
action by another thread moves it from theWaitingstate to theReadystate.
Example: A W AITING thread. We saw an example of this earlier in the multi-
threaded program shown in Figure 4.6 on page 147. After creating a number of
Search WWH ::




Custom Search