Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Deadlock
Synchronization
learning objectives
After completing this chapter, you should be able to describe:
•The basic functionality of the memory allocation methods covered in this chapter:
paged, demand paging, segmented, and segmented/demand paged memory allocation
•The influence that these page allocation methods have had on virtual memory
•The mechanics of paging and how a memory allocation scheme determines which
pages should be swapped out of memory
background
Process
Resource Sharing
Process
M’ment
M’ment Competition for
Problems
limited resources
Problems
Lack of Process Synchronization
Two processes
Each process waiting for I/O request,
One at cylinder 20 and one at cylinder
310.
Deadlock sequence
when R/W arm reaches a track, a
command for other track issued.
Neither I/O request satisfied . Device
puts request on hold while attempting
to fulfill other request
Seven computers on
network
Each on different nodes
Direction of arrows
Indicates message flow
Deadlock sequence
All available buffer space
fills
conditions for deadlock
Four conditions simultaneously occurring prior to deadlock or livelock
no cycles no deadlock.
If graph contains a cycle if only
one instance per resource type,
then deadlock. if several instances
per resource type, possibility of
deadlock.
Complication
every resource cannot be
Complication eliminated from every condition
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 P0 7 4 3
P1 2 0 0 3 2 2 P1 1 2 2
P2 3 0 2 9 0 2 P2 6 0 0
P3 2 1 1 2 2 2 P3 0 1 1
P4 0 0 2 4 3 3 P4 4 3 1
system is currently in a safe state with the sequence < P1, P3, P4, P2, P0>
A B C A B C A B C
P0 0 1 0 7 4 3
P1 3 0 2 0 2 0 2 1 0 ->
P2 3 0 2 6 0 0
P3 2 1 1 0 1 1
P4 0 0 2 4 3 1
Consider , a request for (3,3,0) by P4 cannot be granted, since the resources are not available.
Furthermore, a request for (0,2,0) by P0 cannot be granted, even though the
resources are available, since the resulting state is unsafe.
Given A has 10 instances, B has 5 instances and C has 7 instances
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 0 4 -> 10 5 7 P0 7 4 3
P1 2 0 0 3 2 2 2 1 0 -> 5 3 2 P1 1 2 2
P2 3 0 2 9 0 2 1 4 5 -> 10 4 7 P2 6 0 0
P3 2 1 1 2 2 2 5 2 1 -> 7 4 3 P3 0 1 1
P4 0 0 2 4 3 3 3 1 2 -> 7 4 5 P4 4 3 1
system is currently in a safe state with the sequence < P1, P3, P4, P2, P0>
e r
sw
An
Suppose P1 request - Request1 = (1,0,2).
Initial available = 2 3 0
A B C A B C A B C A B C
P0 0 1 0 7 5 3 7 4 3 0 0 2 -> 7 5 5
P1 3 0 2 3 2 2 0 2 0 2 1 0 -> 5 3 2
P2 3 0 2 9 0 2 6 0 0 1 5 5 -> 10 5 7
P3 2 1 1 2 2 2 0 1 1 5 2 1 -> 7 4 3
P4 0 0 2 4 3 3 4 3 1 3 1 2 -> 7 4 5
Most common
• Job priority under consideration: high-priority jobs usually
untouched
• Example
– “The dining philosophers” by Dijkstra
• Starvation avoidance
– Implement algorithm tracking how long each job waiting for
resources (aging)
– Block new jobs until starving jobs satisfied
the dining philosophers by Dijkstra
The problem is how to design a discipline of behavior (a concurrent algorithm) such that no
philosopher will starve; i.e., each can forever continue to alternate between eating and
thinking, assuming that no philosopher can know when others may want to eat or think.
consider a solution…
Suggest…
This solution to the problem is the one
originally proposed by Dijkstra.
It assigns a partial order to the resources (the forks, in this case), and establishes the
convention that all resources will be requested in order,
and that no two resources unrelated by order will ever be used by a single unit of work
at the same time.
Here, the resources (forks) will be numbered 1 through 5 and each unit of work
(philosopher) will always pick up the lower-numbered fork first, and then the higher-
numbered fork, from among the two forks they plan to use.
The order in which each philosopher puts down the forks does not matter. In this case,
if four of the five philosophers simultaneously pick up their lower-numbered fork, only
the highest-numbered fork will remain on the table, so the fifth philosopher will not be
able to pick up any fork. Moreover, only one philosopher will have access to that
highest-numbered fork, so they will be able to eat using two forks.