Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Concurrency: Deadlock and Starvation II zDeadlock zConditions for Deadlock zDeadlock Prevention zDeadlock Avoidance zBanker’s Algorithm zDeadlock.

Similar presentations


Presentation on theme: "Chapter 6 Concurrency: Deadlock and Starvation II zDeadlock zConditions for Deadlock zDeadlock Prevention zDeadlock Avoidance zBanker’s Algorithm zDeadlock."— Presentation transcript:

1 Chapter 6 Concurrency: Deadlock and Starvation II zDeadlock zConditions for Deadlock zDeadlock Prevention zDeadlock Avoidance zBanker’s Algorithm zDeadlock Detection zStrategies once Deadlock Detected zDeadlock Detection Algorithm zUNIX Concurrency Mechanisms

2 Deadlock Detection zOperating system checks for deadlock zCheck at resource request yearly detection of deadlock yfrequent checks consume processor time zCheck periodically

3 Strategies once Deadlock Detected zAbort all deadlocked processes zBack up each deadlocked process to some previously defined checkpoint, and restart all process yoriginal deadlock may occur zSuccessively abort deadlocked processes until deadlock no longer exists zSuccessively preempt resources until deadlock no longer exists

4 Deadlock Detection Algorithm (1) 1. Mark each process that has a row in the Allocation matrix of all zeros. 2.Initialize a temporary vector W to equal to Available vector. 3. Find an index i such that process i is currently unmarked and the ith row of Q is less than or equal to W. That is, Q ik <= W k, for 1 <= k <= m. If no such row is found, terminate the algorithm. ( Q ik represents the amount of resources of type j requested by process i. m: the amount of resources.) 4. If such a row is found, mark process i and add the corresponding row of the allocation matrix to W. That is, set W k = W k + A ik. Return to step 3. A deadlock exists if and only if there are unmarked processes at the end of the algorithm.

5 Example for Deadlock Detection (2) - Is there any deadlock? R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 1 1 1 0 1 1 0 1 0 0 1 P2 1 1 0 1 1 0 0 0 0 1 0 1 P3 0 0 11 0 0 1 0 0 0 0 1 P4 0 1 01 0 0 0 0 0 1 0 1 P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 1 1 2 1 0 0 0 1 R k = Resource Vector V k = Available Vector

6 Example for Deadlock Detection (3) - Apply the deadlock detection algorithm Step 1 Mark P4 & P5, because P4 & P5 have no allocated resources. R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 1 1 1 0 1 1 0 1 0 0 1 P2 1 1 0 1 1 0 0 0 0 1 0 1 P3 0 0 11 0 0 1 0 0 0 0 1 *P4 0 1 01 0 0 0 0 0 1 0 1 *P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 1 1 2 1 0 0 0 1 R k = Resource Vector V k = Available Vector

7 Example for Deadlock Detection (4) - Apply the deadlock detection algorithm Step 2 and 3 set W = W k = V k = (0 0 0 1) R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 1 1 1 0 1 1 0 1 0 0 1 P2 1 1 0 1 1 0 0 0 0 1 0 1 P3 0 0 11 0 0 1 0 0 0 0 1 *P4 0 1 01 0 0 0 0 0 1 0 1 *P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 1 1 2 1 0 0 0 1 R k = Resource Vector W =W k = V k = Available Vector

8 Example for Deadlock Detection (5) - Apply the deadlock detection algorithm Step 4 The request of process P3 is less than or equal to w, so mark P3 and set W = W + A = (0 0 0 1) + ( 0 0 1 0) = ( 0 0 1 1) R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 1 1 1 0 1 1 0 1 0 0 1 P2 1 1 0 1 1 0 0 0 0 1 0 1 *P3 0 0 11 0 0 1 0 0 0 0 1 *P4 0 1 01 0 0 0 0 0 1 0 1 *P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 1 1 2 1 0 0 0 1 R k = Resource Vector V k = Available Vector

9 Example for Deadlock Detection (6) - Apply the deadlock detection algorithm Step 3 Can not find a row of Q is less than or equal to W. Terminate. P1 & P2 unmarked, indicating these processes are deadlocked. R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 1 1 1 0 1 1 0 1 0 0 1 P2 1 1 0 1 1 0 0 0 0 1 0 1 *P3 0 0 11 0 0 1 0 0 0 0 1 *P4 0 1 01 0 0 0 0 0 1 0 1 *P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 1 1 2 1 0 0 0 1 R k = Resource Vector V k = Available Vector

10 Question 3 - Exercise/Home Work (1) - Is there any deadlock? R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 2 0 1 1 0 0 1 0 2 0 0 1 P2 3 0 1 1 2 0 0 1 1 0 1 0 P3 2 2 20 0 1 2 0 2 1 0 0 P4 0 1 01 0 0 0 0 0 0 0 0 P5 0 0 0 0 0 0 0 0 0 0 0 0 Claim Matrix Allocation Matrix Request Matrix C ik A ik Q ik 4 2 3 1 2 1 0 0 R k = Resource Vector V k = Available Vector

11 UNIX Concurrency Mechanisms zSignals ysoftware mechanism that informs a process of the occurrence of asynchronous events

12 UNIX Concurrency Mechanisms zPipes ycircular buffer allowing two processes to communicate yqueue written by one process and read by another yoperating system enforces mutual exclusion for writing and reading the pipe ywrite requests are immediately executed if there is room in the pipe, otherwise the process is blocked yread request is blocked if attempts to read more bytes than currently in the pipe

13 UNIX Concurrency Mechanisms zMessage Queue yblock of text with accompanying type yreceiver can either retrieve messages in FIFO order or by type yprocess suspends when trying to send a message to a full queue yprocess suspends when reading from an empty queue yprocess trying to read a certain type fails, it’s not suspended

14 UNIX Concurrency Mechanisms zSemaphores ywait and signal yoperating system handles all these requests

15 UNIX Concurrency Mechanisms zShared memory ycommon block of virtual memory shared by multiple processes yfast form of interprocess communication ymutual exclusion must be provided by the processes, not the operating system

16 Question 4 - Exercise/Home Work (1) Consider a system with a total of 150 units of memory, allocated to three processes as shown: Process Max Hold 1 70 45 260 40 36015 Apply the Deadlock Detection and Banker’s algorithm to determine whether it would be safe to grant each of the following requests. If yes, indicate a sequence of termination that could be guaranteed possible. If no, show the reduction of the resulting allocation table. a. A fourth process arrives, with a maximum memory need of 60 and an initial need of 25 units. b. A fourth process arrives, with a maximum memory need of 60 and an initial need of 35 units.


Download ppt "Chapter 6 Concurrency: Deadlock and Starvation II zDeadlock zConditions for Deadlock zDeadlock Prevention zDeadlock Avoidance zBanker’s Algorithm zDeadlock."

Similar presentations


Ads by Google