Professional Documents
Culture Documents
OS 5 Deadlocks
OS 5 Deadlocks
of ALLthe processes in the systems such that for each P,, the resources that Pjcan still request can be satisfied by currently available resources and resources held by all the P,, with j< i — That is: + If P, resource needs are not immediately available, then P, can wait until all P; have finished * When P;is finished, P; can obtain needed resources, execute, return allocated resources, and terminate * When P, terminates, P;,, can obtain its needed resources, and so on [] | | | | “Deadlock avoidance... * Safe and unsafe states... — Example * State at (a) is safe. Why? — There is a sequence of allocation that allows all processes to complete BoC->A — Exercise * If Arequests and gets 1 resource (i.e., A Has 4 resources and Free is 2), can we find a sequence that is guaranteed to work? Has Max Has Max Has Max Has Max Has Max A] 3 9 A] 3 9 A] 3 9 Al 3 9 A 3 9 BI] 2 4 BI 4 4 B Oo} - B]O - B 0 - ci 2 7 Cc} 2 7 Cc} 2 7 c}|7 7 cjo - Free: 3 Free: 1 Free: 5 Free:0 Free: 7 (a) (b) (o) (d) (e) fH »Deadlock avoidance... ¢ Safe and unsafe states... — Unsafe state is not a deadlocked state — From unsafe state, there is no guarantee that all processes will finish [] | | | | *Deadlock avoidance... ¢ Banker’s algorithm for multiple resource — Combines the deadlock detection algorithm for multiple resources with the concept of safe and unsafe state — If a request leads to unsafe state, it must be deferred for a while — Limitation * Processes rarely know in advance what their maximum resource needs will be * Number of processes is not fixed * Resources which were available at one time, may not be available in another time [] | | | | 7Deadlock avoidance... — Example Allocation Max Available Need ABC ABC ABC ABC Po o10 753 332 743 Ries 200) 322 122 Po 302 902 600 eet 222 011 Ps 002 433 431 * And now consider what happens if process P1 requests 4 instance of A and 2 instances of C. | Request 1] =(1,0,2)) Allocation Need Available ABC ABC ABC 010 743 230 302 020 302 600 21a: oll 002 431 * What about requests of ( 3, 3,0) by P4? or (0, 2, 0) by PO? Can these be safely granted? Why or why not?