More IPCBarriersDining Philosophers (1)Posix Library Implementation Based F. Mueller’s PaperDining Philosophers ExampleDining PhilosophersSlide 7The Sleeping Barber Problem (1)Sleeping Barber Problem01/14/19 1More IPCB.Ramamurthy01/14/19 2Barriers•Use of a barrier–processes approaching a barrier–all processes but one blocked at barrier–last process arrives, all are let through01/14/19 3Dining Philosophers (1)•Philosophers eat/think•Eating needs 2 forks•Pick one fork at a time •How to prevent deadlock01/14/19 4Posix Library ImplementationBased F. Mueller’s PaperLanguage ApplicationLanguage Interface C Language ApplicationPosix thread libraryUnix KernelUnix librariesUser LevelKernel LevelTo answer Hanumanth’s question.01/14/19 5Dining Philosophers Examplemonitor dp {enum {thinking, hungry, eating} state[5];condition self[5];void pickup(int i) // following slidesvoid putdown(int i) // following slidesvoid test(int i) // following slidesvoid init() {for (int i = 0; i < 5; i++)state[i] = thinking;}}01/14/19 6Dining Philosophersvoid pickup(int i) {state[i] = hungry;test[i];if (state[i] != eating)self[i].wait();}void putdown(int i) {state[i] = thinking;// test left and right neighborstest((i+4) % 5);test((i+1) % 5);}01/14/19 7Dining Philosophersvoid test(int i) {if ( (state[(I + 4) % 5] != eating) && (state[i] == hungry) && (state[(i + 1) % 5] != eating)) {state[i] = eating;self[i].signal();}}01/14/19 8The Sleeping Barber Problem (1)01/14/19 9Sleeping Barber ProblemThe barber shop has one barber, one barber chair, and n waiting chairs.If there are no customers, barber falls asleep. When customer arrives he/she has to wake up sleeping barber.If additional customer arrive when barber is cutting they wait (if any empty chair) or leave (if all chairs are
View Full Document