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:

  1. 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].

 Trace the Dining Philosopher problem and write the flow of states

+ 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!