Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We have an implementation of Dinning Philosophers in Java. It includes DiningPhilosophers.java that creates and starts threads, PhilosopherThread.java that starts a thread for each philosopher,
We have an implementation of Dinning Philosophers in Java. It includes DiningPhilosophers.java that creates and starts threads, PhilosopherThread.java that starts a thread for each philosopher, and PhilosopherTable java that includes methods pickup() putdown() and test() that look like the following. Fill in the missing code (indicated by - blanki-) public -blank2- void putdown(int i) { setState(i, -blank3-); test(right(i)); testC-blank4-); } public synchronized void pickup(int i) throws InterruptedException { setStateci, State. HUNGRY); -blank1-3 while (state[i] != State. EATING) { this.wait(); // Recheck condition in loop, // since we might have been notified // when we were still hun } private synchronized void test(int i) { if (state[left(i)] != State.EATING && blank5- !=-blank6- && state[i] - State. HUNGRY) } setState(i, -blank7-); // Wake up all waiting threads this.notifyAllo; } } -blank1- [ Choose ] -blank1- -blank2- [Choose ] synchronized left(0) State.EATING State.THINKING state[right] test(i) State.HUNGRY -blank3- -blank4- [Choose ] -blank5- [ Choose -blank6- [Choose ] 4 -blank7- [Choose ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started