Question: Trace the Dining Philosopher problem and write the flow of states using table below. If philosophers 2 , 3 and 5 try to eat. me:
- Trace the Dining Philosopher problem and write the flow of states using table below. If philosophers 2 , 3 and 5 try to eat.
me: semaphore, initially 1; /* for mutual exclusion */
s[5]: semaphore s[5], initially 0; /* for synchronization */
pflag[5]: {THINK, HUNGRY, EAT}, initially THINK; /* philosopher flag */
procedure philosopher(i)
{
while TRUE do
{
THINKING;
take_chopsticks(i);
EATING;
drop_chopsticks(i);
}
}
procedure take_chopsticks(i)
{
P(me); /* critical section */
pflag[i] = HUNGRY;
test[i];
V(me); /* end critical section */
P(s[i]) /* Eat if enabled */
}
void test(i) /* Let phil[i] eat, if waiting */
{
if ( pflag[i] == HUNGRY && pflag[i-1] != EAT && pflag[i+1] != EAT)then
{
pflag[i] = EAT;
V(s[i])
}
}
void drop_chopsticks(int i)
{
P(me); /* critical section */
pflag[i]=THINKING;
test(i-1); /* Let phil. on left eat if possible */
test(i+1); /* Let phil. on right eat if possible */
V(me); /* up critical section */
}
Write the change in state of philosophers [T,E,H] . Initially all are in the thinking state[T].

+ Write the change in state of philosophers [T,E,H] . Initially all are in the thinking state[T]. P[1] P[2] P[4] P[5] T T T T T P[3] O + Write the change in state of philosophers [T,E,H] . Initially all are in the thinking state[T]. P[1] P[2] P[4] P[5] T T T T T P[3] O
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
