The goal of this assignment is to practice concurrent and distributed programming using the JOCAML programming language.
Consider the famous Dinning Philosophers problem. A round table holds n forks and a bowl of spaghetti. Each fork is placed between two seats. The table seats n philosophers, each of whom eats for a while, then thinks for a while, then eats and so on. Each philosopher requires two forks-the ones on the left and right- to eat, but releases them when thinking. The main problem is that without some kind of coordination the philosophers could starve when they pick up their left forks and then block forever trying to pick up the right forks which are being held by other philosophers.Algorithm for philosopher:
Loop forever {
Pick up the fork on the left.
Pick up the fork on the right.
Eat.
Release the fork on the left.
Release the fork on the right.
Think.
}
A solution described by Hoare adds the requirement that at most n-1 philosophers are allowed to be seated at once. This ensures that at all times, at least one philosopher can eat, so there are no deadlocks. This solution assumes there is a bouncer that does not allow a philosopher to sit if there are already n-1 philosophers sitting. You are to write a program simulating this solution. Your program should generate verbose output explaining what is happening.
softFailure()
Don't allow any other philosophers to enter the lounge.
For each philosopher p in the room
Tell p to leave.
After all have left, allow philosophers to enter again.
hardFailure()The bouncer should then check periodically if all philosophers are still alive (using a heart-beating protocol). If not, he/she should generate new philosophers so that there are always n philosophers in the system.
Don't allow any other philosophers to enter the lounge.
For each philosopher p in the room
Kill p.
After all have been killed, allow philosophers to enter again.
You may also want to give a time argument to these failures, so that the failure (or time-bomb) does not happen until that time has elapsed.
Submission:
The due date for this project is April 19th, 2006, 11:55pm EST. You should
use the assignments drop-off box located at the course's WebCT page. Upload
a ZIP file containing all the relevant documented Jocaml files, along
with a README file describing the project and its usage. 24-hour late
submissions will receive a 10% grade penalty, 3-day late submissions will
receive a 25% penalty. Assignments will not be received after April
22th, 2006.