Chapter 6: Q8E (page 568)
Question: The dining philosopher’s problem is a classic problem of synchronization and concurrency. The 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. There is a bowl of pasta in the center. A fork is placed in between each philosopher. The result is that each philosopher has one fork to her left 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 left and right. The philosophers do not speak to one another.
6.8.1 [10] Describe the scenario where none of the philosophers ever eats (i.e., starvation). What is the sequence of events that happen that lead up to this problem?
6.8.2 [10] how we can solve this problem by introducing the concept of a priority? But can we guarantee that we will treat all the philosophers fairly? Explain.
6.8.3 [10] 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. The 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 5 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 [10]If we implement requests to the waiter by periodically repeating our request until the resources become available, will this solve the problem described in Exercise 6.8.3? Explain.
Short Answer
Starvation can occur if forks are not available for the philosophers.
We can solve starvation problem by using a priority queue, but we cannot guarantee fairness because the assignment of forks depend on the priority.
Even if priority queue is implemented and the philosopher is at the head queue, sometimes we cannot provide forks because the adjacent philosophers may not have the forks available.
Even if they send requests periodically, this will not completely solve the problem.