Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is one solution to solve the Dining Philosopher problem based on monitor and conditional variable. Please use one example to trace its execution.

 

Below is one solution to solve the Dining Philosopher problem based on monitor and conditional variable. Please use one example to trace its execution. #define N enum status (EATING, HUNGRY, THINKING); monitor dining Philosophers { status state [N]; condition self [N]; test (int i) { if ((state [(i-1) mod N] != EATING) && (state [i] HUNGRY) && (state [(i+1) mod N] != EATING)) { state [i] EATING; self [i].signal (); } }; public: dining Philosophers () { // Initilization. for (int i = 0; i < N; i++) state[i] = THINKING; }; test (int i) { if ((state [ (i-1) mod N] != EATING) && (state[i] == HUNGRY) && (state (i+1) mod N] != EATING)) { state[i] EATING; self [i].signal(); }; }; public: dining Philosophers () {...}; OpickUpForks (int i) { }; state [i] = HUNGRY; test (i); if (state[i] != EATING) self [i].wait(); put DownForks (int i) { state [i] THINKING; test ((i-1) mod N); test ((i+1) mod N); }; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Factor by grouping. x 2 + 3x - 3y - xy

Answered: 1 week ago

Question

Is there anything else you would like us to know about you?

Answered: 1 week ago