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.

136 Resource Deadlock Chapter 4the request has been granted. There are n ! (n factorial, orn × (n − 1) × (n − 2) × ... × 2 × 1) sequences of n processes, all of which would betried before the state is pronounced unsafe. However, this cost can be reduced to workproportional to n 2 . If the state is safe and if some process A can finish given thecurrently available resources, there is a safe sequence that starts with A. We do not missthe only solutions by starting with a reasonable-looking first element. The O(n 2 ) algorithm(the ‘‘O’’ means ‘‘order of’’) looks roughly like this:1 S := [all the processes];2 while S [] do3 find A, an element of S that can finish4 if impossible, fail: the state is unsafe5 remove A from S, add A’s resources to the unallocated pool6 end;7 succeed: the state is safe.The resource manager need not allocate resources to requesting processes according tothe order of the safe sequence. It may allocate resources in the order of requests as longas there exists some safe sequence after each request is satisfied.The advance-claim algorithm can be applied with a still cheaper algorithmdeveloped by Habermann. The resource manager maintains an array S[0..r − 1] ofintegers, where r is the number of copies of the resource. For simplicity, we assume thatthere is only one resource class. Initially, S[i ] = r − i for all 0 ≤ i

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

Saved successfully!

Ooh no, something went wrong!