ch02.5 - Explain - Excercise - Deadlock
ch02.5 - Explain - Excercise - Deadlock
ch02.5 - Explain - Excercise - Deadlock
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Operating System Concepts – 10th Edition 5a.2 Silberschatz, Galvin and Gagne ©2018
1
System Model
Operating System Concepts – 10th Edition 5a.3 Silberschatz, Galvin and Gagne ©2018
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
Operating System Concepts – 10th Edition 5a.4 Silberschatz, Galvin and Gagne ©2018
2
Avoidance Algorithms
Single instance of a resource type
• Use a modified resource-allocation graph
Multiple instances of a resource type
• Use the Banker’s Algorithm
Ensure the system is safe
Operating System Concepts – 10th Edition 5a.5 Silberschatz, Galvin and Gagne ©2018
Safe State
When a process requests an available resource, system must decide if
immediate allocation leaves the system in a safe state
System is in safe state if there exists a sequence
P1, P2, …, Pn
of ALL the processes in the systems such that for each Pi, the
resources that Pi can still request can be satisfied by currently
available resources + resources held by all the Pj, with j < I
Need [i,j] = Max[i,j] – Allocation [i,j]
Available= Available + Allocation [i,j]
That is:
• If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished
• When Pj is finished, Pi can obtain needed resources, execute,
return allocated resources, and terminate
• When Pi terminates, Pi +1 can obtain its needed resources, and so
on
Operating System Concepts – 10th Edition 5a.6 Silberschatz, Galvin and Gagne ©2018
3
Ex0
Consider a system with 12 magnetic tape drives and 3 processes P1, P2, P3.
• Requires maximum tape drives: P1: 10, P2: 4; P3: 9
• Suppose that at time t1: P1 is holding 5; P2 is holding 2; P3 is holding 3.
At time t1, system is in:
• A.safe state
• B. unsafe state
• C. deadlocked state
• D. starvation state
Expl Max Holding Need
• 2 tape are free. P1 10 5 5
• P2. execute, free 4 tape P2 4 2 2
• 4 tape can not fulfill for P1 or P3 P3 9 3 6
• option (B) is correct.
Operating System Concepts – 10th Edition 5a.7 Silberschatz, Galvin and Gagne ©2018
Ex1
Operating System Concepts – 10th Edition 5a.8 Silberschatz, Galvin and Gagne ©2018
4
Ex1
Use the Banker’s Algorithm
Work
1520
1532
----
2886
2 14 11 8
2 14 12 12
3 14 12 12 (P1)
Operating System Concepts – 10th Edition 5a.9 Silberschatz, Galvin and Gagne ©2018
Ex1
P1 request (0,4,2,0).
• Need(P1) = (0, 7, 5, 0)
5
Ex2
Operating System Concepts – 10th Edition 5a.11 Silberschatz, Galvin and Gagne ©2018
Ex3
Consider the following snapshot of a system:
Operating System Concepts – 10th Edition 5a.12 Silberschatz, Galvin and Gagne ©2018
6
Ex4
Giải thuật Banker - Điền số liệu (có giải thích) vào các bảng sau. Có tồn tại
chuỗi cấp phát an toàn hay không ?. Cho biết tài nguyên ban đầu của hệ
thống.
P1 1 1 1 1 1 4 2 2 3 3 1 2 1 1 1
p2 1 1 0 1 1 2 2 2 2 3
P3 0 0 0 1 1 3 1 1 4 1
P4 1 2 1 1 0 2 4 4 3 2
P5 1 0 0 0 1 2 1 1 1 1
P6
0 2 1 0 1 2 3 2 1 2
Operating System Concepts – 10th Edition 5a.13 Silberschatz, Galvin and Gagne ©2018
Test_1
Operating System Concepts – 10th Edition 5a.14 Silberschatz, Galvin and Gagne ©2018
7
Test_2
• Answer (c)
Operating System Concepts – 10th Edition 5a.15 Silberschatz, Galvin and Gagne ©2018
Test_3
A system shares 9 tape drives. The current allocation and maximum
requirement of tape drives for 4 processes are shown below:
Which of the following best describes the current state of the system?
• A. Safe, Deadlocked
• B. Safe, Not Deadlocked
• C. Not Safe, Deadlocked
• D. Not Safe, Not Deadlocked
Expl: 9 tapes and allocated (3+1+3+0 =) 7 => available tapes are 9 - 7 = 2.
• P1,2 require: not satisfied
• P3 requires 2 tapes => available=5
• P2 requires 5 tapes => available= 6
• P1 requires 6 tapes => available= 9.
• P4 requires 10 => not satisfied
• (C) is correct.
Operating System Concepts – 10th Edition 5a.16 Silberschatz, Galvin and Gagne ©2018
8
Test_4
Operating System Concepts – 10th Edition 5a.17 Silberschatz, Galvin and Gagne ©2018
Test_5
Consider the following snapshot of a system:
Operating System Concepts – 10th Edition 5a.18 Silberschatz, Galvin and Gagne ©2018
9
Ex1, using Resource allocation graph
Is system deadlock
Operating System Concepts – 10th Edition 5a.19 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 5a.20 Silberschatz, Galvin and Gagne ©2018
10
Ex2
unsatisfied “requests”
Operating System Concepts – 10th Edition 5a.21 Silberschatz, Galvin and Gagne ©2018
Ex2
P1’s Request = [0,0,1,0,1]. Run
Available = [3,1,2,3,1]+[1,1,0,0,0] = [4,2,2,3,1].
Operating System Concepts – 10th Edition 5a.22 Silberschatz, Galvin and Gagne ©2018
11
Ex3
Consider the following resource allocation graph
Operating System Concepts – 10th Edition 5a.23 Silberschatz, Galvin and Gagne ©2018
12