13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advance-claim algorithm 137Every time a resource is granted, the process that requested it must have had a claimhigher than the number of resources granted so far, so × will be placed in at least the S[0]column, if not in others. Therefore, the current value of S[0] is the number of availableresources, since we subtract one for each × in the column. If S[0] < 0, the state is notonly unsafe, it is also unrealizable, since more resources have been granted than exist.Next, let us see what happens if a process, say D, claims the entire set of resourcesand then acquires them all. We can see how S is calculated for r = 4:Index 0 1 2 3Original S 4 3 2 1D × × × × D × × × D × ×D ×Final S 0 0 0 0A process that acquires its entire claim makes a triangular ‘‘footprint’’ of × marks in ourpicture. In the case in which the initial claim is the entire set of resources, the footprint islarge enough to reduce every entry in S to 0. When a process has received its entireclaim, the footprint is complete and makes a triangle.Now let us say that one or more entries of S have become −1. For concreteness, letus say that S[3] is the leftmost column with an entry of −1. What is the largest possiblevalue for S[0], S[1], and S[2]? S[2] cannot be greater than 0 — that is, one larger thanS[3] — since every × in column 3 is in a line that also puts × in column 2, and column 2starts only 1 larger than column 3. S[2] cannot be negative, since column 3 was the firstwith a negative value. So S[2] must be 0. Similar reasoning shows that S[1] is either 0or 1, and S[0] is 0, 1, or 2.Since S[2] = 0 and S[3] = −1, there cannot be any line of exactly three × marks.Such a line would have × in column 2 but not in column 3 and therefore would havedecreased S[2] more than S[3], so S[2] would have to be less than 0. Therefore, no footprinthas a line with exactly three × marks. All footprints are either large and incomplete,with their last row having at least four × marks, or they are small, with their first row havingat most two × marks. All the small footprints can finish. They belong to processesthat form the start of a safe sequence. (There are at most two such processes, one with aclaim of 2 and only one line of footprint and one with a claim of 1 and one line of footprint.)After these processes have terminated, S[0] will be 2 and S[1] will be 1. Onlyprocesses with large incomplete footprints are left. Not a single one of them can finish,because each has at least three lines of footprint to complete, so S[0] must be at least 3.But S[0] is only 2. Therefore, there is no safe sequence. This argument does not dependon the fact that we chose column 3 as the first with a negative value.We have been assuming throughout that there is only one resource class. Thesituation becomes more complicated if there are several resource classes. It is notenough to find a safe sequence for each resource class independently; a sequence must befound that is safe with respect to each resource class.The advance-claim algorithm is conservative insofar as it cautiously avoids enteringan unsafe state even if this unsafe state has no deadlock. However, it achieves the

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

Saved successfully!

Ooh no, something went wrong!