


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















CS 241 Spring 2007System Programming
B^ C
Resource Allocation Graph (multiple resource types)
While did not get all resources {^ P(mutex)^ Try to pick up all resources^ if did not get all resources put resources back^ V(mutex)^ wait a while and try again } Use resources P(mutex) Release all resources V(mutex
while need a resource^ {^ P(mutex)^ Test to see if resource is free^ if free, grab resource else release all resources^ V(mutex)^ Wait a while and try again^ }
safe^ state
Available (Banker) Processes^ |^ A B^ | A B | A B |
A B --------------------------------------------------------------------------------------------------------------------- P1^3 0 5
2 3 6 5 P2^2 2 6
4 3 P3^1 3 9
8 5 P4^0 5 8
8 0 Sequence: ^ P1 can go^ (borrows from Banker A(2) and B(3), since Need.A(2) is less than Available A(6) andNeed.B(3) < Available.B(5). After lending, Available will be A(4), B(2)). After P1 finishes it releasesAllocated Resources A(3) and B(0) to the banker, and so the banker will have A(8) = A(6) + A(3) andB(5)=B(5)+B(0) available ^ P2 can go ( borrows from Banker A(4) and B(3)). After P2 finishes it releases the allocated resourceA(1) and B(3) to the banker and available will be A(11), B(7) ^ P3 can go^ (borrows from Banker A(8) and B(5), since Need.A(8) < Available.A(11) and Need.B(5) <Available.B(7)). After P3 finishes, it releases the allocated resources to the banker and Availableresources will be A(12) = A(11) + A(1) and B(10)=B(7+B(3) ^ P4 can go^ because P4 can borrow from Banker Need.A(8) < Available.A(12) andNeed.B(0)<Available.B(10). After P4 finishes, the resources are released, and Banker will haveavailable A(12) and B(15) ^ Hence, there exists a safe sequence with this snapshot of resources and processes. The safesequence is P1, P2, P3, P
-^ let’s assume Max/Need
Max^ Need^ Available (Banker) Processes^ |^ A B^ |^
Sequence: ^ P1 can’t go^ because Need.B(6) > Available.B(5) ^ P2 can’t go^ because Need.A(7) > Available.A(6) ^ P3 can’t go^ because Need.A(8) > Available.A(6) ^ P4 can’t go^ because Need.A(8) > Available.A(6) ^ Hence, there is no safe sequence and this is snapshot is in “unsafe” state