CHAPTER-6 (2)
CHAPTER-6 (2)
DEADLOCKS
2. Resource deadlock:
Suppose process Pi is holding the tape drive and process Pj is
holding the printer.
At any moment of time process Pi needs printer and process Pj
needs tape drive. Thus now Pi requests printer and is holding tape
drive. Process Pj requests tape drive and is holding a printer.
The system is deadlocked because each process holds a resource
being requested by the other process.
DEADLOCK CHARACTERISTICS:
Conditions for deadlock:
1. Mutual exclusion: it means that a resource can be used by only
one process at a time.
2. Hold and wait: the processes involved in deadlock acquire at least
one resource and wait for at least another resource that has been
acquired by another resource.
3. No Preemption: A resource can be released voluntarily by the
process holding it, after that process has completed the task.
4. Circular wait: each process waits for the resource that is held by
the next process in the chain.
RESOURCE ALLOCATION GRAPH:
Graph:
The points of a graph are called vertices or nodes and the lines
connecting the vertices of the graph are called edges or arcs.
The node or vertices that does not have a link with other node is
called isolated node.
A path in a graph is a chain of vertices connected in a sequence.
A cycle is a path where starting and ending node is same.
Resource Allocation graph (RAG):
It is an analytical tool used to describe the deadlock.
Resource allocation graph consist of set of vertices V and a set of
edges E.
The vertices are used to represent the set of processes P and set of
resources R.
There are two types of edges used in RAG
1. Request edge: this edge indicates the request of a process for
acquiring a particular resource.
2. Assignment edge: this edge indicates the allocation of resource to
particular process.
Three process: P1, P2, P3
Four resources: R1, R2, R3, R4
Request edges: P1->R1, P2->R3
Assignment edges: R1->P2, R2->P1, R2->P2, R3->P3
Resource instances: One instance of resource type R1
Two instances of resource type R2
One instance of resource type R3
Three instance of resource type R4
DEALING WITH DEADLOCKS:
1. Deadlock prevention: Measures are taken so that the system does not go
into the deadlock condition in the first place.
2. Deadlock avoidance: before a process is allocated requested resource it
is made sure that the request will not lead to deadlock.
3. Deadlock recovery: it means deadlock occur in the system and then
detect it and recover the system from deadlock.
4. Deadlock ignorance: it saves CPU time and memory space for deadlock
management.
Deadlock Prevention:
We can prevent deadlock by the following conditions:
1. Preventing mutual exclusion:
Mutual exclusion means that resource can be used by only one
process at a time that is it cannot be shared.
We can prevent this condition by making a resource sharable.
When the resources are sharable, they do not require mutually
exclusive.
2. Preventing Hold and Wait:
If we can prevent processes that hold resources from waiting for more
resources, we can eliminate deadlock.
This could be implemented in two ways:
A process should request and acquire resources before its
execution begins.
A process should have released all its resources before it
request for additional resources.
3. Preventing non Preemption:
If a process is holding some resources and requests another resource
that cannot be immediately allocated to it.
This process will now have to wait for the allocation of resources.
4. Preventing Circular wait:
This method ensures that a circular chain of process is not formed in a
system.
DEADLOCK AVOIDANCE:
Safe state and unsafe state:
A state is safe if the system can allocate resources to each
process in some order and still avoid a deadlock.
A system is said to be in a safe state if there is a safe execution
sequence.
Disadvantages:
The algorithm requires that each process must specify its resources
requirement.
It also involves the overhead of simulation and calculation before
each time a process request a resource.