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

NOTE: NEED EXPLANATION.......... monitor code…what follows is pseudocode for cal

ID: 3583779 • Letter: N

Question

NOTE: NEED EXPLANATION..........

monitor code…what follows is pseudocode for calling the routines*/
Each philosopher i invokes the operations pickup() and putdown() in the following
sequence:
DiningPhilosophers.pickup(i);
EAT
DiningPhilosophers.putdown(i);
Question 3.
a. How many philosophers can eat at the same time, and how does the “test” routine make
this possible?
b. On the other hand, how does the “test” routine preserve the condition of a monitor that
only one process can be active within the monitor at one time? Hint: would “Eating” be
considered to be a state or an activity? What about pickup? What about putdown?

Explanation / Answer

a)

From the above given pseudo code, it was clear that a particular philosopher will pick up the fork and after completing eating he will leave the fork this is because other philosophers are waiting to eat. The number of forks given is equal to the number of philosophers at the dining table....

Now for 'n' number of pilosopher maximum of 'n/2' can eat at the same time this is because consider n=4 such that there will be 4 forks available which can be used by maximum of 2 users to eat hence there will be only 2 philosophers can eat at the same time

b) Eating is a state where as pickup and putdown are activities...

void test(int i) {

if ( state[i] == HUNGRY && state[LEFT(i)] != EATING && state[RIGHT(i)] != EATING )

{

state[i] = EATING;

V(s[i]);

}

}

void pickup(int i) {

P(mutex); state[i] = HUNGRY;

test(i);

V(mutex);

P(s[i]);

}

void putdown(int i) {

P(mutex);

state[i]= THINKING;

test(LEFT(i));

test(RIGHT(i));

V(mutex);

}

Here every time a call to the test routine was done inside the lock done by mutex. i.e., after P(mutex) which locks other processes and enable only one process to be active within the monitor at one time after the work is done it will release the lock which enables any other processes to be active at that time.