Successfully reported this slideshow.



Published on


Published in: Education, Technology
  • Be the first to comment


  1. 1. Dining- Philosophers Problem
  2. 2. Dining- Philosophers Problem <ul><li>The philosophers share a circular table surrounded by five chairs, each belonging to one philosopher </li></ul><ul><li>In the center of table is a bowl of rice, and the table is laid with 5 single chopsticks </li></ul><ul><li>From time to time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest to her </li></ul><ul><li>When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks </li></ul><ul><li>When she is finished eating, she puts down both her chopsticks and starts thinking </li></ul>
  3. 3. Dining- Philosophers Problem
  4. 4. Dining- Philosophers Problem
  5. 5. Dining- Philosophers Problem <ul><li>Methods to avoid deadlock: </li></ul><ul><li>Allow at most four philosophers to be sitting simultaneously </li></ul><ul><li>Allow a philosopher to pick up her chopsticks only if both chopsticks are available (pick them up is a critical section) </li></ul>
  6. 6. Problems with Semaphores <ul><li>signal (mutex) //violate mutual exclusive </li></ul><ul><li>critical section </li></ul><ul><li>wait (mutex) </li></ul><ul><li>wait (mutex) //deadlock occurs </li></ul><ul><li>critical section </li></ul><ul><li>wait (mutex) </li></ul><ul><li>Omitting of wait (mutex) or signal (mutex) (or both) </li></ul>
  7. 7. Solution to Dining Philosophers
  8. 8. Solution to Dining Philosophers
  9. 9. Solution to Dining Philosophers <ul><li>Each philosopher I invokes the operations pickup() and putdown() in the following sequence: </li></ul><ul><li>dp.pickup(i) </li></ul><ul><li>EAT </li></ul><ul><li>dp.putdown(i) </li></ul>