Professional Documents
Culture Documents
Chapter7 MultipleResources
Chapter7 MultipleResources
q That you mention their source, after all, I would like people to use my book!
q That you note that they are adapted from (or perhaps identical to)
my slides, and note my copyright of this material.
2.1 Deadlocks
2.2 Deadlock Prevention
2.3 Deadlock Avoidance
2.4 The Dining Philosophers
2.5 Hold and Wait Strategy
2.5 Wait and Release Strategy
2.6 Randomized algorithms
account A account B
Bridge crossing
15×14+1 = 211
5!(4!×4!) = (5!×5!)/5
q Problems
m May not know all required resources in advance.
m Inefficient : ties up resources other processes
could be using.
m Starvation is possible.
q Phase one
mThe process tries to lock all the resources it
currently needs, one at a time
m if needed record is not avaliable, release
and start over
q Phase two: when phase one succeeds,
m performing updates
m releasing locks
“livelock” is possible.
Time stamps:
q Before a process starts locking a unique new
timestamp is associated with that process.
q If a process has been assigned timestamp Ti
and later a new process has assigned
timestamp Tj then Ti <Tj.
q We associate with each resource a
timestamp value, which is the timestamp of
the process that is currently holding that
resource.
1 2 3 4 5 6 7
time
account A account B
safe
unsafe
time
deadlock
All terminated!
Chapter 7 Synchronization Algorithms and Concurrent Programming 20
Gadi Taubenfeld © 2014
Basic Facts
q If a system is in safe state è no deadlock.
Maximum
P1 1 9
P2 4 5
P3 2 8
available : 2
Allocation
Allocation
Allocation
Allocation
Maximum
Maximum
Maximum
Maximum
Maximum
P1 1 9 P1 1 9 P1 1 9 P1 1 9 P1 1 9
P2 4 5 P2 5 5 P2 0 - P2 0 - P2 0 -
P3 2 8 P3 2 8 P3 2 8 P3 8 8 P3 0 -
available : 2 available : 1 available : 6 available : 0 available : 8
P1 9 9 P1 0 --
P2 0 -- P2 0 --
P3 0 -- P3 0 --
available : 0 available : 9
time
Chapter 7 Synchronization Algorithms and Concurrent Programming 23
Gadi Taubenfeld © 2014
Example: safe and unsafe
Allocation
Maximum
P1 1 9
q If process P1 requests one (out of the 2 avaliable),
P2 4 5
resources the Banker will not allocated it.
P3 2 8
available : 2
P1 2 9 unsafe
state
P2 4 5
P3 2 8
available : 1
L L
L L
1 2
R
L R
6 3
R R
R
5 4
Chapter 7 Synchronization Algorithms and Concurrent Programming 31
Gadi Taubenfeld © 2014
The Hold and Wait Strategy
Section 7.5
R R
L L
1 4
R
L L
6 2
R R
L
3 5
R L
L R
free
R L
L R
3 2
L
R L
0 1
L R
L
5 6
L L
q Recall: There is no 4-robust
algorithm using a hold and wait R
strategy.