Lecture 3
Lecture 3
Chapter 6
7
Agenda
• Principles of Deadlock
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• An Integrated Deadlock Strategy
• Dining Philosophers Problem
• Linux Kernel Concurrency
Mechanisms
8
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
9
• A common example is the traffic deadlock.
10
11
• In particular, if all four cars wish to go straight
through the intersection, the resource
requirements are as follows:
• Car 1, traveling north, needs quadrants a and
b.
• Car 2 needs quadrants b and c.
• Car 3 needs quadrants c and d.
• Car 4 needs quadrants d and a.
12
• Joint progress diagram , illustrates the
progress of two processes competing for
two resources. Each process needs exclusive
use of both resources for a certain period of
time.
• Two processes, P and Q, have the following
general form:
13
14
• The figure shows six different execution paths.
These can be summarized as follows:
15
• The gray-shaded area of Figure which can be
referred to as a fatal region , applies to the
commentary on paths 3 and 4.
•
• If an execution path enters this fatal region, then
deadlock is inevitable. Note that the existence of a
fatal region depends on the logic of the two
processes.
16
• Whether or not deadlock occurs depends on both
the dynamics of the execution and on the details
of the application.
17
This situation is reflected in this Figure.
Some thought should convince you that regardless of the relative timing of
the two processes, deadlock cannot occur.
18
19
Reusable Resources
• Used by only one process at a time and not
depleted by that use
• Processes obtain resources that they later
release for reuse by other processes
• Examples of reusable resources are Processors,
I/O channels, main and secondary memory,
devices, and data structures such as files,
databases, and semaphores
• Deadlock occurs if each process holds one
resource and requests the other
20
As an example of deadlock involving reusable resources,
consider two processes that compete for exclusive access to a
disk file D and a tape drive T.
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);
25
26
Resource Allocation Graphs
• Directed graph that depicts a state of the
system of resources and processes
27
Within a resource node, a
dot is shown for each
instance of that resource.
28
-------- 29
Agenda
Principles of Deadlock
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• An Integrated Deadlock Strategy
• Dining Philosophers Problem
• Linux Kernel Concurrency
Mechanisms
30
Conditions for Deadlock
• Mutual exclusion
– Only one process may use a resource at a time
• Hold-and-wait
– A process may hold allocated resources while
awaiting assignment of others
• No preemption
– No resource can be forcibly removed form a
process holding it
31
• 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
32
Three general approaches exist for dealing with deadlock.
First, one can prevent deadlock by adopting a policy that eliminates one
of the conditions (conditions 1 through 4).
35
Deadlock Prevention
• No Preemption
– Process must release resource and request
again
– Operating system may preempt a process to
require it releases its resources
• Circular Wait
– The circular-wait condition can be prevented by
Defineing a linear ordering of resource types.
(If a process has been allocated resources of type R, then it may
subsequently request only those resources of types following R in
the ordering.) 36
Deadlock Prevention
37
38
Deadlock Avoidance
• In deadlock prevention , we constrain resource
requests to prevent at least one of the four
conditions of deadlock.
41