1. Trang chủ
  2. » Công Nghệ Thông Tin

chương 7 hệ điều hành

45 460 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 45
Dung lượng 1,97 MB

Nội dung

Chapter 7: Deadlocks Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Chapter 7: Deadlocks s System Model s Deadlock Characterization s Methods for Handling Deadlocks s Deadlock Prevention s Deadlock Avoidance s Deadlock Detection s Recovery from Deadlock Operating System Concepts – 9th Edition 7.2 Silberschatz, Galvin and Gagne ©2013 Chapter Objectives s To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks s To present a number of different methods for preventing or avoiding deadlocks in a computer system Operating System Concepts – 9th Edition 7.3 Silberschatz, Galvin and Gagne ©2013 System Model s System consists of resources s Resource types R1, R2, , Rm CPU cycles, memory space, I/O devices s Each resource type Ri has Wi instances s Each process utilizes a resource as follows: q request q use q release Operating System Concepts – 9th Edition 7.4 Silberschatz, Galvin and Gagne ©2013 Deadlock Characterization Deadlock can arise if four conditions hold simultaneously s s s s Mutual exclusion: only one process at a time can use a resource Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0 Operating System Concepts – 9th Edition 7.5 Silberschatz, Galvin and Gagne ©2013 Deadlock with Mutex Locks s Deadlocks can occur via system calls, locking, etc s See example box in text page 318 for mutex deadlock Operating System Concepts – 9th Edition 7.6 Silberschatz, Galvin and Gagne ©2013 Resource-Allocation Graph A set of vertices V and a set of edges E s V is partitioned into two types: q P = {P1, P2, …, Pn}, the set consisting of all the processes in the system q R = {R1, R2, …, Rm}, the set consisting of all resource types in the system s request edge – directed edge Pi → Rj s assignment edge – directed edge Rj → Pi Operating System Concepts – 9th Edition 7.7 Silberschatz, Galvin and Gagne ©2013 Resource-Allocation Graph (Cont.) s Process s Resource Type with instances s Pi requests instance of Rj s Pi is holding an instance of Rj Pi Rj Pi Rj Operating System Concepts – 9th Edition 7.8 Silberschatz, Galvin and Gagne ©2013 Example of a Resource Allocation Graph Operating System Concepts – 9th Edition 7.9 Silberschatz, Galvin and Gagne ©2013 Resource Allocation Graph With A Deadlock Operating System Concepts – 9th Edition 7.10 Silberschatz, Galvin and Gagne ©2013 Example of Banker’s Algorithm s processes P0 through P4; resource types: A (10 instances), B (5instances), and C (7 instances) Snapshot at time T0: Allocation Max Available ABC ABC ABC P0 010 753 332 P1 200 322 P2 302 902 P3 211 222 P4 002 433 Operating System Concepts – 9th Edition 7.31 Silberschatz, Galvin and Gagne ©2013 Example (Cont.) s The content of the matrix Need is defined to be Max – Allocation Need ABC P0 P1 122 P2 600 P3 011 P4 s 743 431 The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria Operating System Concepts – 9th Edition 7.32 Silberschatz, Galvin and Gagne ©2013 Example: P1 Request (1,0,2) s Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2) ⇒ true Allocation ABC P0 P1 Need ABC ABC 010 743 230 302 Available 020 P2 302 600 P3 211 011 P4 002 431 s Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies safety requirement s Can request for (3,3,0) by P4 be granted? s Can request for (0,2,0) by P0 be granted? Operating System Concepts – 9th Edition 7.33 Silberschatz, Galvin and Gagne ©2013 Deadlock Detection s Allow system to enter deadlock state s Detection algorithm s Recovery scheme Operating System Concepts – 9th Edition 7.34 Silberschatz, Galvin and Gagne ©2013 Single Instance of Each Resource Type s Maintain wait-for graph q Nodes are processes q Pi → Pj if Pi is waiting for Pj s Periodically invoke an algorithm that searches for a cycle in the graph If there is a cycle, there exists a deadlock s An algorithm to detect a cycle in a graph requires an order of n operations, where n is the number of vertices in the graph Operating System Concepts – 9th Edition 7.35 Silberschatz, Galvin and Gagne ©2013 Resource-Allocation Graph and Wait-for Graph Resource-Allocation Graph Operating System Concepts – 9th Edition 7.36 Corresponding wait-for graph Silberschatz, Galvin and Gagne ©2013 Several Instances of a Resource Type s Available: A vector of length m indicates the number of available resources of each type s Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process s Request: An n x m matrix indicates the current request of each process If Request [i][j] = k, then process Pi is requesting k more instances of resource type Rj Operating System Concepts – 9th Edition 7.37 Silberschatz, Galvin and Gagne ©2013 Detection Algorithm Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b) For i = 1,2, …, n, if Allocationi ≠ 0, then Finish[i] = false; otherwise, Finish[i] = true Find an index i such that both: (a) Finish[i] == false (b) Requesti ≤ Work If no such i exists, go to step Operating System Concepts – 9th Edition 7.38 Silberschatz, Galvin and Gagne ©2013 Detection Algorithm (Cont.) Work = Work + Allocationi Finish[i] = true go to step If Finish[i] == false, for some i, ≤ i ≤ n, then the system is in deadlock state Moreover, if Finish[i] == false, then Pi is deadlocked Algorithm requires an order of O(m x n2) operations to detect whether the system is in deadlocked state Operating System Concepts – 9th Edition 7.39 Silberschatz, Galvin and Gagne ©2013 Example of Detection Algorithm s s Five processes P0 through P4; three resource types A (7 instances), B (2 instances), and C (6 instances) Snapshot at time T0: Allocation ABC P0 Request ABC ABC 000 000 010 P1 200 202 P2 303 000 P3 211 100 002 002 P4 s Available Sequence will result in Finish[i] = true for all i Operating System Concepts – 9th Edition 7.40 Silberschatz, Galvin and Gagne ©2013 Example (Cont.) s P2 requests an additional instance of type C Request ABC P0 P1 202 P2 001 P3 100 P4 s 000 002 State of system? q Can reclaim resources held by process P0, but insufficient resources to fulfill other processes; requests q Deadlock exists, consisting of processes P1, P2, P3, and P4 Operating System Concepts – 9th Edition 7.41 Silberschatz, Galvin and Gagne ©2013 Detection-Algorithm Usage s When, and how often, to invoke depends on: q How often a deadlock is likely to occur? q How many processes will need to be rolled back?  one s for each disjoint cycle If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock Operating System Concepts – 9th Edition 7.42 Silberschatz, Galvin and Gagne ©2013 Recovery from Deadlock: Process Termination s Abort all deadlocked processes s Abort one process at a time until the deadlock cycle is eliminated s In which order should we choose to abort? Priority of the process How long process has computed, and how much longer to completion Resources the process has used Resources process needs to complete How many processes will need to be terminated Is process interactive or batch? Operating System Concepts – 9th Edition 7.43 Silberschatz, Galvin and Gagne ©2013 Recovery from Deadlock: Resource Preemption s Selecting a victim – minimize cost s Rollback – return to some safe state, restart process for that state s Starvation – same process may always be picked as victim, include number of rollback in cost factor Operating System Concepts – 9th Edition 7.44 Silberschatz, Galvin and Gagne ©2013 End of Chapter Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013

Ngày đăng: 10/07/2016, 09:51

TỪ KHÓA LIÊN QUAN

w