Professional Documents
Culture Documents
ACTIVITY - 05
B
Deadlock
R
Deadlock is a situation which involves the interaction of more than one
resource and processes with each other. We can visualise the occurrence of
TH
deadlock as a situation where there are two people on a staircase. One is
ascending the staircase while the other is descending.
The staircase is so narrow that it can only fit one person at a time. As a result,
one has to retreat while the other moves on and uses the staircase. Once that
person has finished, the other one can use that staircase. But here, neither
U
When a process requests for the resource that is being held by another
process which needs another resource to continue, but is being held by the
AM
first process, then it is called a deadlock. There are four conditions necessary
for the occurrence of a deadlock.
They can be understood with the help of the above illustrated example of
staircase:
1. Mutual Exclusion: When two people meet in the landings, they can’t
just walk through because there is space only for one person. This
condition allows only one person (or process) to use the step between
them (or the resource) is the first condition necessary for the occurrence
of the deadlock.
2. Hold and Wait: When the two people refuse to retreat and hold their
ground, it is called holding. This is the next necessary condition for
deadlock.
3. No Preemption: For resolving the deadlock one can simply cancel one
of the processes for others to continue. But the Operating System
doesn’t do so. It allocates the resources to the processors for as much
time as is needed until the task is completed. Hence, there is no
temporary reallocation of the resources. It is the third condition for
deadlock.
4. Circular Wait: When the two people refuse to retreat and wait for each
B
other to retreat so that they can complete their task, it is called circular
wait. It is the last condition for deadlock to occur.
R
Note: All four conditions are necessary for deadlock to occur. If any single one
is prevented or resolved, the deadlock is resolved.
TH
How to OVERCOME a deadlock
1. Process Termination:
R
To eliminate the deadlock, we can simply kill one or more processes. For this,
we use two methods:
AM
● (b) Rollback:
We must determine what should be done with the process from which
B
resources are preempted. One simple idea is total rollback. That means
abort the process and restart it.
R
● (c) Starvation:
In a system, it may happen that the same process is always picked as a
victim. As a result, that process will never complete its designated task.
TH
This situation is called Starvation and must be avoided. One solution is
that a process must be picked as a victim only a finite number of times.
U
R
AM
2. Identify relationships between threads and processes.
Process
Processes are basically the programs that are dispatched from the ready state
and are scheduled in the CPU for execution. PCB(Process Control Block)
holds the concept of process. A process can create other processes which are
known as Child Processes. The process takes more time to terminate and it is
isolated, meaning it does not share the memory with any other process.
The process can have the following states new, ready, running, waiting,
B
terminated, and suspended.
Thread
R
Thread is the segment of a process which means a process can have
multiple threads and these multiple threads are contained within a process. A
TH
thread has three states: Running, Ready, and Blocked.
The thread takes less time to terminate as compared to the process but unlike
the process, threads do not isolate.
U
It also takes more time for It takes less time for context
4.
context switching. switching.
The process is less
Thread is more efficient in terms of
5. efficient in terms of
communication.
communication.
B
A Thread is lightweight as each
The process is called the
8. thread in a process shares code,
heavyweight process.
data, and resources.
R
Process switching uses Thread switching does not require
9. an interface in an calling an operating system and
operating system. causes an interrupt to the kernel.
TH
If one process is blocked
If a user-level thread is blocked, then
then it will not affect the
10. all other user-level threads are
execution of other
blocked.
U
processes
Types of Threads
B
● Advantages of ULT
● Can be implemented on an OS that doesn’t support
multithreading.
R
● Simple representation since thread has only program
counter, register set, stack space.
● Simple to create since no intervention of kernel
TH
● Limitations of ULT
● No or less co-ordination among the threads and Kernel.
● If one thread causes a page fault, the entire process
blocks.
U
each process, the kernel itself has a thread table (a master one) that
keeps track of all the threads in the system. In addition, the kernel also
AM
● Limitations of KLT –
● Slow and inefficient.
● It requires a thread control block so it is an overhead.