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.

134 Resource Deadlock Chapter 4to be liberal enough to make as many loans as possible.We will require that each process make a claim before it acquires any resources.This claim indicates the greatest number of each resource class it will need at any onetime. This claim allows the resource manager to foresee and prevent dangerous situations.The claim can be presented as a service call: Claim(resources). This call returns an error if the process already holdsresources. It sets an upper limit on the number of resources the process may lateruse at one time. The resources argument may list several classes of resources.A process is constrained by its claim; if it ever makes a request that, if satisfied,would cause the process to hold more of some resource class than its initial claim, therequest is rejected. The sum of all the claims made by all the processes can be muchlarger than the total amount of resources available. However, no one process may claimmore than the total number of physical resources because there would be a danger thatthis process could then legally request more than can be granted, and the process wouldnot be able to continue.The resource manager records the current allocation state for each resource class.For simplicity, we will assume that there is only one resource class, like tape drives. Thecurrent allocation state can be declared as follows:1 type2 ProcessResourceState =3 record4 Claim : integer;5 Held : integer;6 Request : integer; { if not zero, the process7 is blocked waiting for this many more }8 end;9 AllocationState =10 record11 array 1:NumberOfProcesses of ProcessResourceState;12 Free : integer; { unallocated resources }13 end;<strong>An</strong> allocation state is called realizable if it makes sense — that is, if the following conditionsprevail:(1) No one claim is for more than the total resources available.(2) No process is holding more than its claim.(3) The sum of all the Held fields is not more than the total resources available.Otherwise, the state is called unrealizable. The resource manager ensures that unrealizablestates are never entered. Each claim is checked against the total resources, and eachrequest is checked against the associated claim.A realizable state is safe if it cannot possibly lead to a deadlock. Formally, a stateis safe if there is a sequence of processes, called a safe sequence, such that these threeconditions are met:(1) The first process in the sequence can certainly finish, because even if it shouldrequest all the resources its claim allows, there are enough free resources tosatisfy this request.(2) The second process in the sequence can finish if the first finishes and releaseseverything it now has, because adding what the first has to the free resources cansatisfy the entire claim of the second process.

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

Saved successfully!

Ooh no, something went wrong!