deadlock - illinois institute of technology · 2015. 6. 22. · - new oxford american dictionary...
TRANSCRIPT
![Page 2: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/2.jpg)
- New Oxford American Dictionary
deadlock |ˈdedˌläk| noun 1 [in sing. ] a situation, typically one involving opposing parties, in which no progress can be made : an attempt to break the deadlock.
![Page 3: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/3.jpg)
Traffic Gridlock
![Page 4: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/4.jpg)
Software Gridlock
mtx_A.lock()mtx_B.lock()
# critical section
mtx_B.unlock()mtx_A.unlock()
mtx_B.lock()mtx_A.lock()
# critical section
mtx_B.unlock()mtx_A.unlock()
![Page 5: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/5.jpg)
§ Necessary conditions for Deadlock
![Page 6: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/6.jpg)
i.e., what conditions need to be true (of some system) so that deadlock is possible? (not the same as causing deadlock!)
![Page 7: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/7.jpg)
I. Mutual Exclusion - resources can be held by processes in
a mutually exclusive manner
![Page 8: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/8.jpg)
II. Hold & Wait - while holding one resource (in mutex),
a process can request another resource
![Page 9: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/9.jpg)
III. No Preemption - one process can not force another to give
up a resource; i.e., releasing is voluntary
![Page 10: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/10.jpg)
IV. Circular Wait - resource requests and allocations create a
cycle in the resource allocation graph
![Page 11: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/11.jpg)
§ Resource Allocation Graphs
![Page 12: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/12.jpg)
Process :
Resource :
Request :
Allocation :
![Page 13: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/13.jpg)
P1 P2 P3
R1 R2
R3
Circular wait is absent = no deadlock
![Page 14: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/14.jpg)
All 4 necessary conditions in place; Deadlock!
P1 P2 P3
R1 R2
R3
![Page 15: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/15.jpg)
in a system with only single-instance resources, necessary conditions ⇔ deadlock
![Page 16: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/16.jpg)
Cycle without Deadlock!
P1 P2
P4
R1
R2
P3
![Page 17: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/17.jpg)
not practical (or always possible) to detect deadlock using a graph
— but convenient to help us reason about things
![Page 18: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/18.jpg)
§ Approaches to Dealing with Deadlock
![Page 19: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/19.jpg)
1. Ostrich algorithm (ignore it and hope it never happens)
2. Prevent it from occurring (avoidance) 3. Detection & recovery
![Page 20: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/20.jpg)
§ Deadlock avoidance
![Page 21: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/21.jpg)
¶ Approach 1: eliminate necessary condition(s)
![Page 22: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/22.jpg)
Mutual exclusion? - eliminating mutex requires that all
resources be shareable - when not possible (e.g., disk, printer), can
sometimes use a spooler process
![Page 23: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/23.jpg)
but what about semaphores, file locks, etc.? - not all resources are spoolable - cannot eliminate mutex in general
![Page 24: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/24.jpg)
Hold & Wait? - elimination requires resource requests to be
all-or-nothing affair - if currently holding, needs to release all
before requesting more
![Page 25: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/25.jpg)
in practice, very inefficient & starvation is possible! — cannot eliminate hold & wait
![Page 26: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/26.jpg)
No preemption? - alternative: allow process to preempt each
other and “steal” resources - mutex locks can not be counted on to
stay locked! - in practice, cannot eliminate this either!
![Page 27: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/27.jpg)
Circular Wait is where it’s at.
![Page 28: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/28.jpg)
simple mechanism to prevent wait cycles: - order all resources - require that processes request
resources in order
![Page 29: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/29.jpg)
but impractical — can not count on processes to need resources in a certain order
… and forcing a certain order can result in poor resource utilization
![Page 30: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/30.jpg)
¶ Approach 2: intelligently prevent circular wait
![Page 31: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/31.jpg)
possible to create a cycle (with one edge)?
P1 P2
R1
R2
![Page 32: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/32.jpg)
possible to create a cycle (with one edge)?
P1 P2
R1
R2
![Page 33: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/33.jpg)
P1 P2
R1
R2
it’s quite possible that P2 won’t need R2, or maybe P2 will release R1 before requesting R2,but we don’t know if/when…
![Page 34: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/34.jpg)
preventing circular wait means avoiding a state where a cycle is an imminent possibility
P1 P2
R1
R2
![Page 35: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/35.jpg)
to predict deadlock, we can ask processes to “claim” all resources they need in advance
P1 P2
R1
R2
![Page 36: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/36.jpg)
P1 P2
R1
R2
graph with “claim edges”
![Page 37: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/37.jpg)
P1 P2
R1
R2
P2 requests R1
![Page 38: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/38.jpg)
convert to allocation edge; no cycle
P1 P2
R1
R2
![Page 39: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/39.jpg)
P1 requests R2
P1 P2
R1
R2
![Page 40: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/40.jpg)
if we convert to an allocation edge ...
P1 P2
R1
R2
![Page 41: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/41.jpg)
cycle involving claim edges!
P1 P2
R1
R2
![Page 42: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/42.jpg)
means that if processes fulfill their claims, we cannot avoid deadlock!
P1 P2
R1
R2
![Page 43: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/43.jpg)
i.e., P1 → R1, P2 → R2
P1 P2
R1
R2
![Page 44: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/44.jpg)
P1 → R2 should be blocked by the kernel, even if it can be satisfied with available resources
P1 P2
R1
R2
![Page 45: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/45.jpg)
this is a “safe” state … i.e., no way a process can cause deadlock directly (i.e., without OS alloc)
P1 P2
R1
R2
![Page 46: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/46.jpg)
idea: if granting an incoming request would create a cycle in a graph with claim edges, deny that request (i.e., block the process)
— approve later when no cycle would occur
![Page 47: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/47.jpg)
P2 releases R1
P1 P2
R1
R2
![Page 48: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/48.jpg)
now ok to approve P1 → R2 (unblock P1)
P1 P2
R1
R2
![Page 49: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/49.jpg)
should we still deny P1 → R2?
P1 P2
R1
R2
P3
![Page 50: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/50.jpg)
problem: this approach may incorrectly predict imminent deadlock when resources with multiple instances are involved
![Page 51: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/51.jpg)
requires a more general definition of “safe state”
P1 P2
R1
R2
P3
![Page 52: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/52.jpg)
¶ Banker’s Algorithm
(by Edsger Dijkstra)
![Page 53: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/53.jpg)
basic idea: - define how to recognize system “safety” - whenever a resource request arrives:
- simulate allocation & check state - allocate iff simulated state is safe
![Page 54: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/54.jpg)
some assumptions we need to make: 1. a non-blocked process holding a resource
will eventually release it 2. it is known a priori how many instances of
each resource a given process needs
![Page 55: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/55.jpg)
- There exists a sequence <P1, P2, ..., Pn>, where each Pk can complete with: - currently available (free) resources - resources held by P1...Pk-1
Safe State
![Page 56: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/56.jpg)
Processes P1…Pn, Resources R1…Rm: available[j] = num of Rj available max[i][j] = max num of Rj required by Pi allocated[i][j] = num of Rj allocated to Pi need[i][j] = max[i][j] - allocated[i][j]
Data Structures
![Page 57: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/57.jpg)
1. finish[i] ← false ∀ i ∈ 1…nwork ← available
2. Find i : finish[i] = false & need[i][j] ≤ work[j] ∀ j If none, go to 4.
3. work ← work + allocated[i]; finish[i] ← true Go to 2.
4. Safe state iff finish[i] = true ∀ i
Safety Algorithm
![Page 58: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/58.jpg)
incoming request represented by request array request[j] = num of resource Rj requested
(a process can require multiple instances of more than one resource at a time)
![Page 59: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/59.jpg)
1. If request[j] ≤ need[k][j] ∀ j, continue, else error
2. If request[j] ≤ available[j] ∀ j, continue, else block 3. Run safety algorithm with:
- available ← available - request - allocated[k] ← allocated[k] + request - need[k] ← need[k] - request
Processing Request from Pk:
![Page 60: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/60.jpg)
if safety algorithm fails, do not allocate, even if resources are available!
— either deny request or block caller
![Page 61: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/61.jpg)
A B C
P0 7 5 3
P1 3 2 2
P2 9 0 2
P3 2 2 2
P4 4 3 3
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
Allocated
A B C
3 3 2
Available
A B C
7 4 3
1 2 2
6 0 0
0 1 1
4 3 1
NeedMax
• Safe state: <P1, P3, P0, P2, P4> • P3 requests <0, 0, 1> • P0 requests <0, 3, 0>
3 resources: A (10), B (5), C (7)
![Page 62: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/62.jpg)
¶ Banker’s algorithm discussion
![Page 63: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/63.jpg)
1. Efficiency? - how fast is it? - how often is it run?
![Page 64: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/64.jpg)
1. finish[i] ← false ∀ i ∈ 1…nwork ← available
2. Find i : finish[i] = false & need[i][j] ≤ work[j] ∀ j If none, go to 4.
3. work ← work + allocated[i]; finish[i] ← true Go to 2.
4. Safe state iff finish[i] = true ∀ i
for up to N processes, check M resources
loop for N processes
O(N∙N∙M) = O(N2∙M)
![Page 65: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/65.jpg)
how often to run? - need to run on every resource request - can’t relax this, otherwise system might
become unsafe!
![Page 66: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/66.jpg)
2. Assumption #1: processes will eventually release resources
![Page 67: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/67.jpg)
- assuming well-behaved processes - not 100% realistic, but what else to do?
![Page 68: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/68.jpg)
3. Assumption #2: a priori knowledge of max resource requirements
![Page 69: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/69.jpg)
- highly unrealistic - process resource needs are dynamic! - without this assumption, deadlock
prevention becomes much harder…
![Page 70: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/70.jpg)
¶ Aside: decision problems, complexity theory & the halting problem
![Page 71: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/71.jpg)
a decision problem
input
decision algorithm
yes no
![Page 72: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/72.jpg)
e.g., is X evenly divisible by Y? is N a prime number? does string S contain pattern P?
![Page 73: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/73.jpg)
a lot of important problems can be reworded as decision problems: e.g., traveling salesman problem (find the shortest tour through a graph) ⇒ is there a tour shorter than L?
![Page 74: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/74.jpg)
complexity theory classifies decision problems by their difficulty, and draws relationships between those problems & classes
![Page 75: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/75.jpg)
class P: solutions to these problems can be found in polynomial time (e.g., O(N2))
![Page 76: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/76.jpg)
class NP: solutions to these problems can be verified in polynomial time
— but finding solutions may be harder!(i.e., superpolynomial)
![Page 77: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/77.jpg)
big open problem in CS: P = NP?
![Page 78: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/78.jpg)
why is this important?
![Page 79: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/79.jpg)
all problems in NP can be reduced to another problem in the NP-complete class,
and all problems in NP-complete can be reduced to each other)
![Page 80: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/80.jpg)
if you can prove that any NP-complete problem is in P, then all NP problems are in P!
(more motivation: you also win $1M)
![Page 81: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/81.jpg)
if you can prove P ≠ NP, we can stop looking for fast solutions to many hard problems
(motivation: you still win $1M)
![Page 82: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/82.jpg)
a decision problem
input
decision algorithm
yes no
![Page 83: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/83.jpg)
deadlock prevention
resources available, request & allocations,
running programs
will the system deadlock?
yes no
![Page 84: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/84.jpg)
the halting problem
description of a program and its inputs
will the system halt (or run forever)?
yes no
![Page 85: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/85.jpg)
e.g., write the function:
halt(f) ! bool - return true if f will halt - return false otherwise
![Page 86: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/86.jpg)
def halt(f): # your code here
def loop_forever(): while True: pass
def just_return(): return True
halt(loop_forever) # => False
halt(just_return) # => True
![Page 87: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/87.jpg)
#$^%&#@!!!
def halt(f): # your code here
def gotcha(): if halt(gotcha): loop_forever() else: just_return()
halt(gotcha)
![Page 88: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/88.jpg)
![Page 89: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/89.jpg)
proof by contradiction: the halting problem is undecidable
![Page 90: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/90.jpg)
generally speaking, deadlock prediction can be reduced to the halting problem
![Page 91: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/91.jpg)
i.e., determining if a system is deadlocked is, in general, provably impossible!!
![Page 92: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/92.jpg)
§ Deadlock Detection & Recovery
![Page 93: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/93.jpg)
¶ Basic approach: cycle detection
![Page 94: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/94.jpg)
e.g., Tarjan’s strongly connected components algorithm; O(|V|+|E|)
![Page 95: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/95.jpg)
need only run on mutex resources and “involved” processes
… still, would be nice to reduce the size of the resource allocation graph
![Page 96: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/96.jpg)
actual resources involved are unimportant — only care about relationships between processes
![Page 97: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/97.jpg)
P1 P2 P3
P5
P4
Resource Allocation Graph
![Page 98: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/98.jpg)
P1 P2 P3
P4
P5
“Wait-for” Graph
![Page 99: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/99.jpg)
Substantial optimization!
P1 P2 P3
P5
P4
P1 P2 P3
P4
P5
![Page 100: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/100.jpg)
… but not very useful when we have multi-instance resources (false positives are likely)
![Page 101: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/101.jpg)
¶ Deadlock detection algorithm
![Page 102: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/102.jpg)
important: do away with requirement ofa priori resource need declarations
![Page 103: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/103.jpg)
new assumption: processes can complete withcurrent allocation + all pending requests i.e., no future requests
unrealistic! (but we have no crystal ball)
![Page 104: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/104.jpg)
keep track of all pending requests in: request[i][j] = num of Rj requested by Pi
![Page 105: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/105.jpg)
1. finish[i] ← all_nil?(allocated[i]) ∀ i ∈ 1…nwork ← available
2. Find i: finish[i] = false & request[i][j] ≤ work[j] ∀ j If none, go to 4.
3. work ← work + allocated[i]; finish[i] ← trueGo to 2.
4. If finish[i] ≠ true ∀ i, system is deadlocked.
Detection algorithm ignore processes that aren’t allocated anything
![Page 106: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/106.jpg)
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 3
P3 2 1 1
P4 0 0 2
A B C
0 0 0
2 0 2
0 0 0
1 0 0
0 0 2
Allocated Request
A B C
0 0 0
Available
3 resources: A (7), B (2), C (6)
• Not deadlocked: <P0, P2, P1, P3, P4> • P2 requests <0, 0, 1>
![Page 107: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/107.jpg)
¶ Discussion
![Page 108: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/108.jpg)
1. Speed?
![Page 109: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/109.jpg)
1. finish[i] ← all_nil?(allocated[i]) ∀ i ∈ 1…nwork ← available
2. Find i: finish[i] = false & request[i][j] ≤ work[j] ∀ j If none, go to 4.
3. work ← work + allocated[i]; finish[i] ← trueGo to 2.
4. If finish[i] ≠ true ∀ i, system is deadlocked.
Still O(N∙N∙M) = O(N2∙M)
![Page 110: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/110.jpg)
2. When to run?
![Page 111: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/111.jpg)
… as seldom as possible! tradeoff: the longer we wait between checks, the messier resulting deadlocks might be
![Page 112: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/112.jpg)
3. Recovery?
![Page 113: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/113.jpg)
One or more processes must release resources: - via forced termination - resource preemption - system rollback
cool, but how?
![Page 114: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/114.jpg)
Resource preemption only possible with certain types of resources
- no intermediate state - can be taken away and returned (while
blocking process) - e.g., mapped VM page
![Page 115: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/115.jpg)
Rollback requires process checkpointing: - periodically autosave/reload process state - cost depends on process complexity - easier for special-purpose systems
![Page 116: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/116.jpg)
How many to terminate/preempt/rollback? - at least one for each disjoint cycle
- non-trivial to determine how many cycles and which processes!
![Page 117: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/117.jpg)
Selection criteria (who to kill) = minimize cost - # processes - completed run-time - # resources held / needed - arbitrary priority (no killing system
processes!)
![Page 118: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/118.jpg)
Dealing with deadlock is hard!
![Page 119: Deadlock - Illinois Institute of Technology · 2015. 6. 22. · - New Oxford American Dictionary deadlock |㷦ded㷧läk| noun 1 [in sing. ] a situation, typically one involving opposing](https://reader033.vdocuments.site/reader033/viewer/2022060903/609f639effff582fdb3b6a6f/html5/thumbnails/119.jpg)
Moral of this and the concurrency material: - be careful with concurrent resource sharing - use concurrency mechanisms that avoid
explicit locking whenever possible!