Page 72 - DCAP103_Principle of operating system
P. 72
Unit 3: Process Management-II
3.1.6 Disadvantages of Threads over Multiple Processes Notes
• Blocking: The major disadvantage is that if the kernel is single threaded, a system call of
one thread will block the whole process and CPU may be idle during the blocking period.
• Security: Since there is an extensive sharing among threads there is a potential problem
of security. It is quite possible that one thread over writes the stack of another thread (or
damaged shared data) although it is very unlikely since threads are meant to cooperate
on a single task.
3.1.7 Application that Benefits from Threads
A proxy server satisfying the requests for a number of computers on a LAN would be benefited
by a multi-threaded process. In general, any program that has to do more than one task at a
time could benefit from multitasking. For example, a program that reads input, process it, and
outputs could have three threads, one for each task.
3.1.8 Application that cannot Benefit from Threads
Any sequential process that cannot be divided into parallel task will not benefit from thread, as
they would block until the previous one completes. For example, a program that displays the
time of the day would not benefit from multiple threads.
3.1.9 Resources Used in Thread Creation and Process Creation
When a new thread is created it shares its code section, data section and operating system
resources like open files with other threads. But it is allocated its own stack, register set and a
program counter.
Figure 3.1
Thread A
Thread creation
Thread B
Thread C
The creation of a new process differs from that of a thread mainly in the fact that all the shared
resources of a thread are needed explicitly for each process. So though two processes may be
running the same piece of code they need to have their own copy of the code in the main memory
to be able to run. Two processes also do not share other resources with each other. This makes
the creation of a new process very costly compared to that of a new thread.
A virus is also a thread in operating system.
3.2 Context Switch
To give each process on a multiprogrammed machine a fair share of the CPU, a hardware clock
generates interrupts periodically. This allows the operating system to schedule all processes in
main memory (using scheduling algorithm) to run on the CPU at equal intervals. Each time a
LOVELY PROFESSIONAL UNIVERSITY 65