Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6.8 The dining philosopher’s problem is a classic problem of synchronization and

ID: 3809653 • Letter: 6

Question

6.8 The dining philosopher’s problem is a classic problem of synchronization and concurrency. e general problem is stated as philosophers sitting at a round table doing one of two things: eating or thinking. When they are eating, they are not thinking, and when they are thinking, they are not eating. ere is a bowl of pasta in the center. A fork is placed in between each philosopher. e result is that each philosopher has one fork to her le and one fork to her right. Given the nature of eating pasta, the philosopher needs two forks to eat, and can only use the forks on her immediate le and right. e philosophers do not speak to one another.

6.8.1 Describe the scenario where none of philosophers ever eats (i.e., starvation). What is the sequence of events that happen that lead up to this problem?

6.8.2 Describe how we can solve this problem by introducing the concept of a priority. Can we guarantee that we will treat all the philosophers fairly? Explain.

Now assume we hire a waiter who is in charge of assigning forks to philosophers. Nobody can pick up a fork until the waiter says they can. e waiter has global knowledge of all forks. Further, if we impose the policy that philosophers will always request to pick up their le fork before requesting to pick up their right fork, then we can guarantee to avoid deadlock.

6.8.3 We can implement requests to the waiter as either a queue of requests or as a periodic retry of a request. With a queue, requests are handled in the order they are received. e problem with using the queue is that we may not always be able to service the philosopher whose request is at the head of the queue (due to the unavailability of resources). Describe a scenario with ve philosophers where a queue is provided, but service is not granted even though there are forks available for another philosopher (whose request is deeper in the queue) to eat.

6.8.4 Ifweimplementrequeststothewaiterbyperiodicallyrepeating our request until the resources become available, will this solve the problem described in Exercise 6.8.3? Explain.

Explanation / Answer

Solution:

Before discussing about the situation let's discuss what Dining Philosopher problem exactly is

Dining Philosopher: So dining philosopher problem states that there are several philosopher's are available on single rounded table and they are here to have some food, but the problem is they have limited number of forks available i.e same number as philosopher's are available and they cannot eat using one fork, a philosopher needs exactly two forks to have food. SO how will they manage and have food.

Well, in dining philosopher's problem there are several scenarios which needs to be discussed in this case:

To understand it better, suppose the philosophers are taking spaghetti to eat and they have endless supply of spaghetti and are put into a room for 28 days..

Please note that it doesn't matter that how much supply of spaghetti is until people are eating them and by people I mean ALL of them

Scenario: 1

In this scenario, what will happen is all the five philosopher's picked up there right fork at the same time. Now, no one has the left fork to eat in this case everyone will starve to death in 28 days, and none of the spaghetti will be consumed irrespective of the supply.

Scenario: 2

In this scenario, what will happen that suppose philosopher's make a pact together to solve this problem and have food since they are starving, what they decide is to have spaghetti alternatively so using four forks two philosopher's sitting in front of each other will take there turn and have delicious spaghetti, but in this case one of our philosopher is sitting ideal observing the whole scene and very soon he will die ho hunger.

Scenario: 3

Here one of our philosopher gets greedy and decides to eat spaghetti on his own will without caring for anybody else,so in this case two of the philosopher's will die of starvation and one greedy philosopher will become way healthy.

Scenario 4:

If we assign a conductor to maintain that no philosopher die, so whenever a fork is required to a philosopher he will raise his/her hand left or right for the respective fork and conductor checks whether the forks are available then grant permission to the philosopher's to eat. in this scenario no philosopher will Die. But the problem occurs when all the philosopher's request for the fork at the same time, That situation is called deadlock.