SlideShare a Scribd company logo
Please trace the execution of the following solution to the Dining Philosopher problem.
#define N ___
enum status(EATING, HUNGRY, THINKING};
monitor diningPhilosophers {
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:
diningPhilosophers() { // 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:
diningPhilosophers() {...};
pickUpForks(int i) {
state[i] = HUNGRY;
test(i);
if(state[i] != EATING) self[i].wait();
};
putDownForks(int i) {
state[i] = THINKING;
test((i-1) mod N);
test((i+1) mod N);
};
}

More Related Content

More from admin463580

Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
admin463580
 
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdfplease show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
admin463580
 

More from admin463580 (12)

Please solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdfPlease solve the following problem- Create a program that allows disce.pdf
Please solve the following problem- Create a program that allows disce.pdf
 
Please solve Question 9- 8- P the.pdf
Please solve Question 9-  8- P the.pdfPlease solve Question 9-  8- P the.pdf
Please solve Question 9- 8- P the.pdf
 
Please show your work! Draw an UML class diagram showing the classes.pdf
Please show your work!   Draw an UML class diagram showing the classes.pdfPlease show your work!   Draw an UML class diagram showing the classes.pdf
Please show your work! Draw an UML class diagram showing the classes.pdf
 
Please simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdfPlease simply answer the questions below using Internet research (Scho.pdf
Please simply answer the questions below using Internet research (Scho.pdf
 
Please solve (b) The frequency distribution of heights of 100 college.pdf
Please solve  (b) The frequency distribution of heights of 100 college.pdfPlease solve  (b) The frequency distribution of heights of 100 college.pdf
Please solve (b) The frequency distribution of heights of 100 college.pdf
 
Please show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdfPlease show the work for this question- The Voyager spacecraft has bee.pdf
Please show the work for this question- The Voyager spacecraft has bee.pdf
 
please show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdfplease show the work to the numerical example i need help The Network.pdf
please show the work to the numerical example i need help The Network.pdf
 
Please show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdfPlease show that L is regular by creating a DFA- Consider the followin.pdf
Please show that L is regular by creating a DFA- Consider the followin.pdf
 
please type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdfplease type all answers asap- i dont have figures- just do it without (1).pdf
please type all answers asap- i dont have figures- just do it without (1).pdf
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdfplease show elegoo arduino board setup using a passive buzzer- heres t.pdf
please show elegoo arduino board setup using a passive buzzer- heres t.pdf
 
Please translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdfPlease translate this into MIPS Assembly without using Psuedo-instruct.pdf
Please translate this into MIPS Assembly without using Psuedo-instruct.pdf
 

Recently uploaded

plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

Please trace the execution of the following solution to the Dining Phi.pdf

  • 1. Please trace the execution of the following solution to the Dining Philosopher problem. #define N ___ enum status(EATING, HUNGRY, THINKING}; monitor diningPhilosophers { 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: diningPhilosophers() { // 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;
  • 2. self[i].signal(); }; }; public: diningPhilosophers() {...}; pickUpForks(int i) { state[i] = HUNGRY; test(i); if(state[i] != EATING) self[i].wait(); }; putDownForks(int i) { state[i] = THINKING; test((i-1) mod N); test((i+1) mod N); }; }