Deadlock
Deadlock
& AVOIDANCE
OF DEAD LOCKS IN AN OS
INTRODUCTION TO
DEADLOCKS
FOR DEADLOCK
held by other processes.
No Preemption: Resources cannot be forcibly
removed from the processes holding them.
Circular Wait: A set of processes are waiting for
each other in a circular chain.
DEADLOCK
PREVENTION TECHNIQUES
Eliminate Mutual Exclusion:
allowing multiple processes to access the same resource
simultaneously .
Example: Use read-only files for multiple readers.
Eliminate Hold and Wait:
Ensure processes request all the required resources at once.
Example: Two-phase locking protocol.
Eliminate No Preemption:
Allow preemption of resources.
Example: Rollback of processes if required.
Eliminate Circular Wait:
Impose an ordering on resource acquisition.
Example: Number resources and ensure processes request resources
in ascending order.
DEADLOCK AVOIDANCE
TECHNIQUES
Single instance of a resource type
Use a resource-allocation graph
A safe state means the system can run all the processes without getting stuck or running out of resources
Resource Allocation Graph
(RAG)
Nodes: Represent processes (P1, P2, ...)
and resources (R1, R2, ...).
Edges:
Request Edge (P → R): A process
requests a resource.
Assignment Edge (R → P): A resource
is allocated to a process.
Claim edge (Pi → Rj) indicated that
process Pj may request resource Rj;
represented by a dashed line.
Resource Allocation Graph
(RAG)
Suppose that process Pi requests a resource Rj