Detailed Notes on Deadlocks
Detailed Notes on Deadlocks
1. Introduction to Deadlocks
Definition:
Deadlock is a situation in a multiprogramming environment where a set of processes are
blocked because each process is holding a resource and waiting for another resource held
by another process.
Example:
A law in Kansas required two trains approaching a crossing to stop, and neither could
move until the other did—this exemplifies a deadlock.
2. System Model
Resources:
A system consists of several types of resources such as CPU cycles, memory, files, and
I/O devices. Each type can have multiple instances.
Sequence of Resource Usage:
1. Request: A process requests a resource.
2. Use: The process uses the resource.
3. Release: The process releases the resource after use.
Resource Allocation:
3. Deadlock Characterization
Deadlock can only occur if all the following conditions are true:
1. Mutual Exclusion:
At least one resource must be non-sharable (only one process can use it at a time).
Example: A printer.
2. Hold and Wait:
A process holding at least one resource is waiting for more resources held by others.
3. No Preemption:
Resources cannot be forcibly taken from a process; they must be released voluntarily.
4. Circular Wait:
A closed chain of processes exists where each process holds a resource needed by the
next.
Illustration:
P1→R1→P2→R2→P1 forms a circular wait.
Components:
o Processes: Circles.
o Resources: Rectangles with dots representing instances.
o Edges:
Request Edge (P→RP \to RP→R): Process requests a resource.
Assignment Edge (R→PR \to PR→P): Resource assigned to a process.
Graph Analysis:
o Cycle Present:
Single instance per resource → Deadlock.
Multiple instances → Possible deadlock.
Most operating systems, such as Linux and Windows, ignore deadlocks under the
assumption they rarely occur.
4.2. Prevention
1. Mutual Exclusion:
Use sharable resources.
Example: Read-only files.
2. Hold and Wait:
Processes must request all resources at once or release held resources before requesting
new ones.
Drawbacks: Low resource utilization, starvation possible.
3. No Preemption:
Allow resources to be forcibly taken and reallocated.
Example: Preempting CPU registers.
4. Circular Wait:
Impose an ordering on resource requests and require processes to request resources in
increasing order.
4.3. Avoidance
5. Deadlock Prevention
Mutual Exclusion:
Cannot always be avoided, as some resources are inherently non-sharable (e.g., mutex
locks).
Hold and Wait:
o Protocols: Request all resources upfront or release current resources before
requesting new ones.
o Issues: Low resource utilization, possible starvation.
No Preemption:
o Resources held by waiting processes are preempted.
o Useful for resources that can be saved and restored (e.g., CPU registers).
Circular Wait:
o Impose a total ordering on resource types.
o Processes request resources in increasing order.
6. Deadlock Avoidance
Issues:
1. Deciding which resources to preempt.
2. Rolling back processes to a safe state.
3. Ensuring no process suffers from starvation.
9. Livelock
Definition: Processes are not blocked but continuously change state without progress.
Example: Two people moving aside repeatedly to let the other pass but blocking each
other.
Figures to Include