358 Computer Architecture and Organization
is always under complete control of the OS from the time it is powered on till it is switched off. The OS
lends the processor to some user-process under its supervision and continuously monitors it. How is it
implemented? Well, the OS periodically issues some interrupts and regains the control of the processor.
It may then oversee the situation and take its stock.
To switch from one process to another in, e.g., Round Robin technique, the OS sets up the periodical
interrupt as per the duration of the preset time-slice. Whenever this interrupt is generated, the processor
saves all relevant information of the ongoing process within its PCB and reloads the necessary informa-
tion from the PCB of the next-to-run process from the queue. The mechanism of switching between two
processes A and B is graphically explained through Figure 11.9 .
Figure 11.9 Process switching mechanism between process A and B
In this example, it is assumed that for an ongoing Round Robin scheduling, the OS permitted a
time-slice of 10 milliseconds. This is implemented by setting up regular interrupts at 10 milliseconds.
If during such an interrupt, Process A uses the CPU, its details are saved within its PCB, details from
PCB of Process B (next process of the queue) are loaded and the execution of Process B starts. After
another 10 milliseconds, Process B is terminated and Process A resumes its execution (in case of only
two processes in the queue).
One important point must be noted here. Switching from one process to another is always an extra
overhead for the processor. The method is not an instantaneous one and needs nite amount of CPU
time. Therefore faster process-switching increases this overhead.
11.4 THREADS
In OS, threads are viewed as light-weight processes. In other words, a thread is a process, but with lesser
overhead than the overhead necessary to run a process. To clarify the matter further, we should discuss
an example case.
Let us assume that we have opened a word processor and was busy in typing a letter, periodically
saving it as a new le. Suddenly an urgent message reached us that a small two-line notice (or any
other word document) needed to be immediately printed. What do we do in such a case? We do not
terminate the letter-writing. Rather, we open another new blank document, type the two-liner, and
get it printed. Once the printed document is dispatched, we go back to the original letter and resume
with it.
Observe that the part of the word processor (instruction sets), which is executed or to be executed for
our original word processing work (letter writing), is also necessary for writing the two-line-notice. So,
M11_GHOS1557_01_SE_C11.indd 358M11_GHOS1557_01_SE_C11.indd 358 4/29/11 5:22 PM4/29/11 5:22 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.139.224