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?
![void take forks(int i) { down(&mutex); state[i] = HUNGRY; test(i); } up(&mutex); down(&s[i]); } void](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1696/2/5/1/848651abfc85d7cb1696251846795.jpg)
![void test(i) { /* i: philosopher number, from 0 to N-1 */ if (state[i]= HUNGRY && state[LEFT] != EATING &&](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1696/2/5/1/854651abfcec20261696251853505.jpg)
#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
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
Get step-by-step solutions from verified subject matter experts
