Question: In the solution to the dining philosophers problem (Fig. 2-20), why is the state variable set to HUNGRY in the procedure take_forks? #define N #define

In the solution to the dining philosophers problem (Fig. 2-20), why is the state variable set to HUNGRY in the procedure take_forks?#define N #define LEFT #define RIGHT #define THINKING void philosopher(int i) { } #define HUNGRY #define

void take forks(int i) { down(&mutex); state[i] = HUNGRY; test(i); } up(&mutex); down(&s[i]); } void

void test(i) { /* i: philosopher number, from 0 to N-1 */ if (state[i]= HUNGRY && state[LEFT] != EATING &&

#define N #define LEFT #define RIGHT #define THINKING void philosopher(int i) { } #define HUNGRY #define EATING typedef int semaphore; int state[N]; semaphore mutex = 1; semaphore s[N]; 5 } (i+N-1)%N (i+1)%N eat(); put_forks(i); 0 1 2 while (TRUE) { think(); take_forks(i); /* number of philosophers */ /* number of i's left neighbor */ /* number of i's right neighbor */ /* philosopher is thinking */ /* philosopher is trying to get forks */ /* philosopher is eating */ /* semaphores are a special kind of int */ /* array to keep track of everyone's state */ /* mutual exclusion for critical regions */ /* one semaphore per philosopher */ /* i: philosopher number, from 0 to N-1 */ /* repeat forever */ /* philosopher is thinking */ /* acquire two forks or block */ /* yum-yum, spaghetti */ /* put both forks back on table */

Step by Step Solution

3.27 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The state variable is set to HUNGRY in the takeforks procedure of the solution to the dining philosophers problem to indicate that a philosopher is cu... View full answer

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 Operating Systems Internals And Design Principles Questions!