OS Chapter 6 (Deadlock) (13!4!2020) 1
OS Chapter 6 (Deadlock) (13!4!2020) 1
OS Chapter 6 (Deadlock) (13!4!2020) 1
Starvation
Deadlock and Starvation problems in
concurrent process environment will be
discussed
Reference:
Operating Systems: Internals and Design Principles by Author William
Stallings
Concurrency: Deadlock and
Starvation
• Lecture Contents
– Deadlock and Starvation – Deadlock Avoidance
introduction – Two Approaches to Deadlock
– Deadlock Avoidance
– Reusable and Consumable – Resource Allocation Denial
Resources – The Banker's Algorithm
– Resource Allocation Graphs – Deadlock Avoidance and its
– Conditions for Deadlock conditions
– Possibility of Deadlock – Deadlock Detection
– Existence of Deadlock – Strategies Once Deadlock
– Deadlock Prevention Detected
– Dining Philosophers Problem
Objective and Learning Outcome
• Objective
– The main goal of this lesson is to help students understand the
reasons why deadlock happens, its prevention methods, and
how to recover from a deadlock situation.
• Learning Outcome
– At the end of this lesson the students will be al to understand:
• The reason behind the occurrence of deadlock in computer systems
• The methods and related algorithms used to prevent and avoid the
deadlock condition
• The methods and related algorithms used once deadlock is
detected
Introduction
• Deadlock
– A set of processes is deadlocked when every process
in the set is waiting for a resource that is currently
allocated to another process in the set ( and which
can only be released when that other waiting process
makes progress).
• Starvation
– Starvation is a condition where a process does not
get the resources it needs for a long time because the
resources are being allocated to other processes. It
generally occurs in a Priority based scheduling
System.
Deadlock
• Permanent blocking of a set of processes that
either compete for system resources or
communicate with each other
• No efficient solution
• Involve conflicting needs for resources by two or
more processes
Deadlock
• The figure 6.1, which is of a traffic deadlock,
makes the nature of deadlock very clear.
P1 P2
... ...
Request 80 Kbytes; Request 70 Kbytes;
... ...
Request 60 Kbytes; Request 80 Kbytes;
P1 P2
... ...
Receive(P2); Receive(P1);
... ...
Send(P2, M1); Send(P1, M2);
Resource Allocation Graphs
• Directed graph that depicts a state of the system
of resources and processes
Resource Allocation Graphs
• In some cases deadlocks can be understood more
clearly through the use of Resource-Allocation Graphs,
having the following properties:A set of resource
categories, { R1, R2, R3, . . ., RN }, which appear as
square nodes on the graph. Dots inside the resource
nodes indicate specific instances of the resource. ( E.g.
two dots might represent two laser printers. )
1) Mutual exclusion
– Only one process may use a resource at a time
2) Hold-and-wait
– A process may hold allocated resources while
awaiting assignment of others
Conditions for Deadlock
3) No preemption
– No resource can be forcibly removed form a process
holding it
4)Circular wait
– A closed chain of processes exists, such that each
process holds at least one resource needed by the
next process in the chain
Resource Allocation Graphs
Resource Allocation Graphs
• Mutual Exclusion
• No preemption
• Hold and wait
Existence of Deadlock
• Deadlock can exist if and only if 4 conditions
hold simultaneously:
• Mutual Exclusion
• No preemption
• Hold and wait
• Circular wait
To be continued….