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 5 some insights have been provided towards the implementation of the dining philosopher solution using semaphores at user level. You have to use threads and semaphores(or 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 food/shared resource is 30 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:
1. The philosopher idles for a random amount of time between 2 and 4 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.
2. Then the philosopher tries to acquire the two forks, one on each side.
3. Upon acquiring the forks, the philosopher first checks the remaining amount of shared resource. If the amount is more than 0:
* The philosopher starts to eat: The amount of shared resource is decreased by 1 unit, and the philosophers thread idles for a random amount of time between 1 and 3 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 1. If the amount is 0:
* 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 Silberschatz-Operating System Concepts (9th,2012_12)
Figure 5.18 A monitor solution to the dining-philosopher problem.
monitor DiningPhilosophers
{
enum {THINKING, HUNGRY, EATING} state[5];
condition self[5];
void pickup(int i)
{
state[i]= HUNGRY;
test(i);
if (state[i]!= EATING)
self[i].wait();
}
void putdown(int i){
state[i]= THINKING;
test((i +4)%5);
test((i +1)%5);
}
void test(int i)
{
if ((state[(i +4)%5]!= EATING) &&
(state[i]== HUNGRY) &&
(state[(i +1)%5]!= EATING)){
state[i]= EATING;
self[i].signal();
}
}
initialization code(){
for (int i =0; i <5; i++)
state[i]= THINKING;
}
}
Figure 5.18 A monitor solution to the dining-philosopher problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!