Neil Bergmann at Queensland University of Technology, Australia created this project. Thanks Neil!


The Dining Philosophers

This assignment deals with one of the famous problems in resource allocation, deadlock and synchronization. Copy a proposed solution to the Dining Philosopher's problem, dine.cm (BACI C-- syntax) from the common directory of larkspur. Execute the program 50 times and record how often the philosophers eat and how often they deadlock. (BACI prints out system diagnostics when it detects deadlock, i.e. when all threads in the system are blocked.) Identify the problem that exists in this solution to the Dining Philosophers, and fix the problem such that your solution is independent of the number of philosophers. Execute the program at least 50 times and confirm that deadlock doesn't occur in your solution.

Written deliverables:

  1. A listing of your revised code; highlight the parts of your revised code that are different from the original.
  2. A brief explanation of why the original program deadlocks, and also an explanation of how the diners sometime do manage to eat in this program.
  3. A brief explanation of how your solution corrects the problem discussed in 2., emphasizing why your solution never deadlocks.
  4. An illustration of the results from 50 executions (in a compact format!), which shows that your solution never deadlocks. (You can add a for-loop to the main program outside the cobegin to help make this data collection easier.)
  5. Show the results from your compact 50-executions when you change your program to four dining philosophers and then to three dining philosophers. The only parts of the code that should change for these different executions is the number of calls to dine() in the cobegin/coend block.
  6. A brief explanation to the following three questions:
    1. Is your algorithm robust against deadlock when the number of diners change? Explain.
    2. Is your algorithm fair in the sense that every diner has a chance to be the first to eat? Explain.
    3. If diners took an hour to eat their spaghetti, what is the longest and shortest time that five diners would take to eat using your algorithm? Explain.