0% found this document useful (0 votes)
3 views

Detailed Notes on Deadlocks

The document provides an overview of deadlocks in multiprogramming environments, defining it as a situation where processes are blocked due to resource holding and waiting. It discusses the necessary conditions for deadlocks, methods for handling them including prevention, avoidance, and detection, as well as recovery strategies. Additionally, it introduces concepts such as the Resource-Allocation Graph and the Banker's Algorithm to manage resources effectively and prevent deadlocks.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Detailed Notes on Deadlocks

The document provides an overview of deadlocks in multiprogramming environments, defining it as a situation where processes are blocked due to resource holding and waiting. It discusses the necessary conditions for deadlocks, methods for handling them including prevention, avoidance, and detection, as well as recovery strategies. Additionally, it introduces concepts such as the Resource-Allocation Graph and the Banker's Algorithm to manage resources effectively and prevent deadlocks.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Detailed Notes on Deadlocks (Chapter 8)

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:

o Resources are allocated based on availability.


o If unavailable, the process waits.

3. Deadlock Characterization

3.1. Necessary Conditions for Deadlock

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.

3.2. Resource-Allocation Graph

 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.

4. Methods for Handling Deadlocks

4.1. Ignore the Problem

 Most operating systems, such as Linux and Windows, ignore deadlocks under the
assumption they rarely occur.

4.2. Prevention

Ensure at least one of the four necessary conditions cannot hold:

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

 Use algorithms like Banker’s Algorithm.


 Requires additional information about resource usage in advance.

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

6.1. Safe State

 A system is in a safe state if it can allocate resources without causing a deadlock.


 Unsafe State: May lead to deadlock, but not guaranteed.

6.2. Banker’s Algorithm

 Goal: Ensure the system remains in a safe state.


 Data Structures:
1. Available: Number of available instances of each resource type.
2. Max: Maximum demand of each process.
3. Allocation: Resources currently allocated.
4. Need: Resources still needed (calculated as Max - Allocation).
 Process:
1. Check if the request can be granted.
2. Simulate allocation.
3. Grant the request if the system remains in a safe state.
7. Deadlock Detection

7.1. Single Resource Instance (Wait-for Graph)

 Simplifies detection by collapsing the resource allocation graph.


 Cycle in Wait-for Graph → Deadlock.

7.2. Multiple Resource Instances

 Use matrices like Available, Allocation, and Request to detect deadlock.

8. Recovery from Deadlock

8.1. Process Termination

1. Abort All Deadlocked Processes:


Guarantees deadlock resolution but at a high cost.
2. Abort One Process at a Time:
Requires multiple deadlock detections.

8.2. Resource Preemption

 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

1. Resource-Allocation Graphs (Figures 8.4, 8.5 for deadlock scenarios).


2. Wait-for Graph (Figure 8.11 to explain deadlock detection).
3. Banker’s Algorithm Example (show Max, Allocation, Need matrices with calculations).
Would you like specific practice problems or programming exercises based on this content?

You might also like