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.

128 Resource Deadlock Chapter 4deadlockpossibleavoid deadlockwithforeknowledgeprevent deadlockwithout foreknowledgeliberalconservativeveryexpensivehierarchicalserializationgrant if availableadvance-claim one-shotFigure 4.5 The liberal-conservative spectrumnever grantOur goal is to achieve the most liberal resource-allocation policy we can withoutencountering deadlock. Serialization avoids deadlock but is very conservative. Figure4.5 also shows the resource-allocation policies we will examine. The one-shot, hierarchical,and advance-claim algorithms put increasingly less onerous restrictions on theprocesses that wish to request resources. The advance-claim algorithm also requires acertain amount of prior knowledge about the resources required by each process. Themore information of this nature we know, the closer we can approach our goal. However,the algorithms that make use of such knowledge are increasingly expensive to execute.Before we turn to these other algorithms, we will introduce a particularly instructiveexample of resource allocation.3 DINING PHILOSOPHERSThe classical ‘‘Dining philosophers’’ problem demonstrates both deadlock and starvationissues.Dining philosophers problemFive philosophers are seated around a circular table. Between each pair of adjacentphilosophers is a chopstick, so there are five chopsticks all together. Infront of each philosopher is a bowl of rice. It takes two chopsticks to eat rice,so a philosopher needs to grab both the chopstick to the left and the one to theright in order to start eating. While philosopher n is eating, neither neighbor,that is, neither philosopher n +1 nor n −1, can be eating, because both need achopstick that is in use by philosopher n . Each philosopher thinks for a while,then decides to eat, gets the chopsticks needed, eats, and puts the chopsticksdown again, in an endless cycle. The challenge is to grant requests for chopstickswhile avoiding deadlock and starvation.

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

Saved successfully!

Ooh no, something went wrong!