Menu

[Solved]Write Complete Code C Dining Philosophers Problem Using Monitors Run Please Show Output Us Q37121032

Write the complete code in C for the Dining PhilosophersProblem using Monitors and run it

Please show the output and use the code below

monitor DiningPhilosophers
{
enum {THINKING, HUNGRY, EATING} state[5];
condition self[5];
void pickup(int i) {
state[i] = HUNGRY;
test(i);
if (state[i] != EATING)
self[i].wait();
}
void putdown(int i) {
state[i] = THINKING;
test((i + 4) % 5);
test((i + 1) % 5);
}
void test(int i) {
if ((state[(i + 4) % 5] != EATING) &&
(state[i] == HUNGRY) &&
(state[(i + 1) % 5] != EATING)) {
state[i] = EATING;
self[i].signal();
}
}
initialization code() {
for (int i = 0; i < 5; i++)
state[i] = THINKING;
}
}

Expert Answer


Answer to Write the complete code in C for the Dining Philosophers Problem using Monitors and run it Please show the output and us… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *