SlideShare a Scribd company logo
1 of 2
Download to read offline
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

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 

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); }; }