Question: Could you help me with this project using java In this project you will implement a solution for the dining philosopher problem. At the end
Could you help me with this project using java
In this project you will implement a solution for the dining philosopher problem. At the end of chapter some insights have been provided towards the implementation of the dining philosopher solution using semaphores at user level. You have to use threads and semaphoresor mutex locks to complete the project.
There are seven philosophers and seven forks. You will need seven threads for philosophers and seven semaphores or mutex locks for forks. Your solution implementation has to be deadlock free.
The initial amount of foodshared resource is units.
Two integer variables are associated with each philosopher: thinking duration and eating duration. These variables are initialized to zero.
All philosopher threads should be running before any of them starts trying to eat.
A philosopher thread works as follows:
The philosopher idles for a random amount of time between and seconds figure out a suitable system call to implement this feature Philosopher increments its thinking duration value by the number of seconds for which it idles.
Then the philosopher tries to acquire the two forks, one on each side.
Upon acquiring the forks, the philosopher first checks the remaining amount of shared resource. If the amount is more than :
The philosopher starts to eat: The amount of shared resource is decreased by unit, and the philosophers thread idles for a random amount of time between and seconds. The philosopher also increments its eating duration value by the number of seconds for which it idles while holding its forks.
The philosopher releases the forks and goes back to step If the amount is :
The philosopher thread prints the time spent it spent before getting hungry and the time spent eating for each eating cycle it had. It also prints the final value of its thinking duration eating duration. Then, its thread terminates.
Your program should terminate once all seven philosopher threads have terminated.
The Book we use for this class is Abraham SilberschatzOperating System Concepts th
Figure A monitor solution to the diningphilosopher problem.
monitor DiningPhilosophers
enum THINKING HUNGRY, EATING state;
condition self;
void pickupint i
statei HUNGRY;
testi;
if statei EATING
selfiwait;
void putdownint i
statei THINKING;
testi ;
testi ;
void testint i
if statei EATING &&
statei HUNGRY &&
statei EATING
statei EATING;
selfisignal;
initialization code
for int i ; i ; i
statei THINKING;
Figure A monitor solution to the diningphilosopher problem.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
