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

(c) Dining-Philosophers Problem Consider five philosophers who spend their lives

ID: 3918989 • Letter: #

Question

(c) Dining-Philosophers Problem Consider five philosophers who spend their lives thinking and eating. The philosophers share a common circular table surrounded by five chairs, each belonging to one philosopher. There is a bowl of rice in the center of the table and the table is laid with five single chopsticks as depicted in the Figure 3. When a philosopher thinks, he does not interact with his colleagues. From time to time, a philosopher tries to pick up the chopsticks that are closest. He cannot pick up a chopstick that is already in the hand of another. When finished eating, he puts both chopsticks down Figure 3 The situation of the dining philosophers (Source: Silberschatz, 1999) Algorithm for dining-Philosophers problem //Shared data var chopst1ck: array l0..4J Of semaphore; (-1 initially) //Philosopher i: repeat wait (chopstick[i]) wait (chopstick[itl mod 5]) //eat signal (chopstick[i]) signal (chopstick [ i+1 mod 5]); //think until false; An effective approach to prevent a deadlock is to deny circular wait. Using the (5 marks) algorithm, consider a deadlock situation in the Dining-Philosophers, problem and prove that the deadlock can be averted in the Dining-Philosophers' problem using deny circular wait.

Explanation / Answer

Dear Student,

Algorithm :

When a philosopher wants to eat the rice, he will wait for the chopstick at his left and picks up that chopstick. Then he waits for the right chopstick to be available, and then picks it too. After eating, he puts both the chopsticks down.

But if all five philosophers are hungry simultaneously, and each of them pickup one chopstick, then a deadlock situation occurs because they will be waiting for another chopstick forever. The possible solutions for this are:

Happy Learning :)