13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advance-claim algorithm 133is not so severe as the one-shot rule.The hierarchical allocation rule solves the deadlock problem. To see why, let’s saythat there is a deadlock. We can show that some process must have broken the rules.Pick any member of the deadlock and call it process A. It must be blocked while waitingfor some resource. That resource is at some level, say a. Some process B has thatresource and is waiting for another resource. Since B already has a resource at level a,the one it is waiting for must be at a higher level, say b. This argument continues aroundthe cycle until we find that process A must be holding a resource at level z , where z>a.But then A has broken the rules, because it is asking for a resource at level a. If A hasn’tbroken the rules, then somewhere else along the cycle a mistake was made. To enforce ahierarchical allocation, the resource manager should return an error indication instead ofgranting a resource when a process breaks the rule.In our scenario of Figure 4.1, neither process has followed the hierarchical rule,since both have requested a tape drive after they already have one. Each should requestboth drives simultaneously. If they had followed the rule, they would not have encountereda deadlock. If we wish, we can distinguish the two tape drives and put them at differentlevels. Then both A and B must ask for the lower-level tape drive before thehigher-level one. The second process to ask for its lower-level tape drive will beblocked. Again, deadlock is avoided.The hierarchical strategy also protects the dining philosophers from deadlock. Ifall chopsticks are at the same level, the philosophers must ask for both chopsticks atonce, which we have already seen prevents deadlocks. If each chopstick is at a differentlevel, each philosopher must always ask for the chopsticks in the proper order. It cannothappen that the proper order for every philosopher is to ask first for the left chopstick andthen for the right chopstick.Unfortunately, the hierarchical strategy is still fairly conservative. Processes mustask for low-level resources long before they are really needed because after higher-levelresources have been acquired, it is no longer possible to get low-level resources withoutgiving the high-level ones back. Since resources are acquired in this artificial order,some processes are blocked for resources they don’t need yet but must acquire now.Other processes are blocked for resources they need but are being held by another processthat does not need them yet. In the extreme case in which all resources are at thesame level, hierarchical allocation reduces to the one-shot technique.When hierarchical allocation is used, the scarcest resources are usually given thehighest levels. Requests for them will therefore be made only when they are actuallyneeded by a process.6 ADVANCE-CLAIM ALGORITHMThe advance-claim algorithm moves us closer to our goal of liberalism without deadlockby requiring extra information in advance. Consider a banker with an initial amount ofcash with which to grant loans and customers who wish to take loans and later repaythem. Customers often request additional loans before they can pay back anything. Thebanker must be conservative enough to avoid deadlocks among the customers but wishes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!