Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Dinning Philosopher Problem (MULTI-THREADING with Resource Sharing) There must be 5 philosophers sitting in a round table each with its own parameters: 1. how

The Dinning Philosopher Problem (MULTI-THREADING with Resource Sharing)

There must be 5 philosophers sitting in a round table each with its own parameters:

1. how long does he thinks (in seconds). 2. how long does he eat (in seconds).

When creating the object for the philosophers, these parameters are passed to their constructors. You can ask your user how much to assign for each philosophers.

Rules: 1. All 5 philosophers are sitting in a round table. 2. A philosopher can only eat their spaghetti using a pair of chopsticks (if he can use the left and right chopsticks). 3. Each philosophers can only eat if he has both sticks. 4. There are only 1 chopstick on the left and 1 chopstick on the right in each philosopher's point of view. 5. They share their chopsticks with each other. 7. If he doesn't have both chopsticks, he can not eat and should wait for his neighbor to put down their chopstick so he can eat. 8. When the philosopher is thinking, he puts down his chopsticks. If he gets hungry after thinking, he takes the chopsticks on his left and right to eat.

Example: Philosopher 1 is between Philosopher 5 and Philosopher 2. If both Philosopher 5 and 2 is thinking, 1 has access to both chopsticks in his left and right, so he can eat. If either Philosophers 5 or 2 is eathing, 1 can not eat, as he doesn't have access to one or both of the chopsticks. Therefore, he has to wait for 5 and 2 to stop eating, before he can eat.

Programming task: Simulate this scenario using threading. Each Philosophers should be in their own thread.

Sample output:

Philosopher 1: Thinking for 2 sec... Philosopher 2: Thinking for 3 sec... Philosopher 3: Thinking for 6 sec... Philosopher 4: Thinking for 5 sec... Philosopher 5: Thinking for 4 sec... Philosopher 1: Becomes hungry... Philosopher 1: is now eating for 5 sec... Philosopher 2: Becomes hungry... Philosopher 2: I can't eat. Waiting for the chopsticks... Philosopher 5: Becomes hungry... Philosopher 5: I can't eat. Waiting for the chopsticks... Philosopher 4: Becomes hungry... Philosopher 4: is now eating for 5 sec...

Refer to this video for further info: https://www.youtube.com/watch?v=XjlFoND00oY https://www.youtube.com/watch?v=NbwbQQB7xNQ

Required Submission: 1. JAVA source code. 2. Word Document explaining your strategy on managing the allocation of chopsticks. Use this guide questions: How did you manage the chopsticks? Does your strategy suffers from possible starvation? (one of the philosophers might not be able to eat if his neighbors are being unfair. They keep eating after each other.) Do you think your algorithm in chopsticks management prevents deadlock? (Each have 1 chopstick picked up and everyone is waiting forever)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To solve the dining philosopher problem with Java multithreading we need to ensure fair access to shared chopsticks and avoid deadlock and starvation Below is a stepbystep solution and detailed calcul... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions

Question

=+d) Create the c chart for this two-week period.

Answered: 1 week ago

Question

1. Compare Revenue Rulings with Revenue Procedures.

Answered: 1 week ago

Question

What is really the cause of the conflict?

Answered: 1 week ago