Chapter 06
Chapter 06
Chapter 06
Chapter 6
Concurrency: Deadlock and
Starvation
Dave Bremer
Otago Polytechnic, N.Z.
©2008, Prentice Hall
Roadmap
• Principals of Deadlock
– Deadlock prevention
– Deadlock Avoidance
– Deadlock detection
– An Integrated deadlock strategy
• Dining Philosophers Problem
• Concurrency Mechanisms in UNIX, Linux,
Solaris and Windows
Deadlock
• A set of processes is deadlocked when
each process in the set is blocked awaiting
an event that can only be triggered by
another blocked process in the set
– Typically involves processes competing for
the same set of resources
• No efficient solution
Potential Deadlock
I need I need
quad C quad B and
and B C
I need
I need quad A and
quad D B
and A
Actual Deadlock
HALT until
HALT until B is free
A is free
Two Processes P and Q
• Lets look at this with
two processes P and Q
• Each needing
exclusive access to a
resource A and B for a
period of time
Joint Progress
Diagram of Deadlock
Alternative logic
• Suppose that P does
not need both
resources at the same
time so that the two
processes have this
form
Diagram of
alternative logic
Resource Categories
Two general categories of resources:
• Reusable
– can be safely used by only one process at a
time and is not depleted by that use.
• Consumable
– one that can be created (produced) and
destroyed (consumed).
Reusable Resources
• Such as:
– 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
Example of
Reuse Deadlock
• Consider two processes that compete for
exclusive access to a disk file D and a
tape drive T.
• Deadlock occurs if each process holds
one resource and requests the other.
Reusable Resources
Example
Example 2:
Memory Request
• Space is available for allocation of
200Kbytes, and the following sequence of
events occur
P1 P2
... ...
Request 80 Kbytes; Request 70 Kbytes;
... ...
Request 60 Kbytes; Request 80 Kbytes;
• Circular Wait
– Define a linear ordering of resource types