SlideShare a Scribd company logo
Trace the Dining Philosopher problem and write the flow of states using table below. If
philosophers 2, 3 and 5 try to eat. Write the states of all philosophers whenever there is a change
in
one philosopher state.
Semaphore me= 1; /* for mutual exclusion */
Semaphore s[5], all initially 0; /* for synchronization */
pflag[5]: {THINK, HUNGRY, EAT}, initially THINK; /* philosopher flag */
procedure philosopher(i) //starts here
{
while TRUE do
{
THINKING;
take_chopsticks(i);
EATING;
drop_chopsticks(i);
}
}
procedure take_chopsticks(i)
{
P(me); /* critical section */
pflag[i] = HUNGRY;
test[i];
V(me); /* end critical section */
P(s[i]) /* Eat if enabled */
}
void test(i) /* Let phil[i] eat, if waiting */
{
if ( pflag[i] == HUNGRY && pflag[i-1] != EAT && pflag[i+1] != EAT)then
{
pflag[i] = EAT;
V(s[i])
}
}
void drop_chopsticks(int i)
{
P(me); /* critical section */
pflag[i]=THINKING;
test(i-1); /* Let phil. on left eat if possible */
test(i+1); /* Let phil. on right eat if possible */
V(me); /* up critical section */
}
Write the change in state of philosophers [T,E,H]. Initially all are in the thinking state [T].

More Related Content

PDF
Today Meadowvale Aged Care facility is very short staffed I.pdf
PDF
The US Patent amp Trademark Office spends most of its time.pdf
PDF
The spinner shown above is a fair spinner Event A is define.pdf
PDF
The Movie table has the following columns ID integer pri.pdf
PDF
The figure shows a chromosomal separation taking place What.pdf
PDF
Read the case study below and answer the questions that foll.pdf
PDF
Question 2 Suppose we are given the data X1X2Yx11x12y1x21.pdf
PDF
sadaf has developed a condition called paralytic ileus or p.pdf
Today Meadowvale Aged Care facility is very short staffed I.pdf
The US Patent amp Trademark Office spends most of its time.pdf
The spinner shown above is a fair spinner Event A is define.pdf
The Movie table has the following columns ID integer pri.pdf
The figure shows a chromosomal separation taking place What.pdf
Read the case study below and answer the questions that foll.pdf
Question 2 Suppose we are given the data X1X2Yx11x12y1x21.pdf
sadaf has developed a condition called paralytic ileus or p.pdf

More from abhisheksharmasre (20)

PDF
Af if be abint Quentien 18 Quevioni Guantion 29The secon.pdf
PDF
Question 1 MiniList collection 20 marks In this question .pdf
PDF
Bayan Mahta Amiri uzun yllara dayanan deneyime sahip bir Se.pdf
PDF
Bir stma paraziti plazmodyum tr bir krmz kan hcresini i.pdf
PDF
Angela is an artist who puts together an exhibit of modern a.pdf
PDF
Describe two detection methods for exoplanets other than the.pdf
PDF
Case Study WGM employs many employees in several departments.pdf
PDF
3 1 point Let PA03PB04PBA01 Find PAB.pdf
PDF
Cul de las siguientes describe MEJOR las caractersticas d.pdf
PDF
1 How to calculate COGS and Ending Inventory using either t.pdf
PDF
PLEASE HELP Refer to the HarrisTodaro migration model As.pdf
PDF
prepare a chart Part 1 Stakeholder Register Choose a proj.pdf
PDF
1 Explain the role of each of the following in HIV infectio.pdf
PDF
1 As you work towards a final transaction name three items.pdf
PDF
PERT ve CPM ile ilgili olarak aadaki ifadelerden hangisi dor.pdf
PDF
Please write it in C not python .pdf
PDF
Mary Lou eitim tasarruf hesabndan 8000 lk bir datm ald v.pdf
PDF
If a profit maximizing monopolist operates where P1 and th.pdf
PDF
fy1 y2 y3 5 Let Y1Y2 and Y3 be three continuous rando.pdf
PDF
On the basis of the financial ratios and benchmarking inform.pdf
Af if be abint Quentien 18 Quevioni Guantion 29The secon.pdf
Question 1 MiniList collection 20 marks In this question .pdf
Bayan Mahta Amiri uzun yllara dayanan deneyime sahip bir Se.pdf
Bir stma paraziti plazmodyum tr bir krmz kan hcresini i.pdf
Angela is an artist who puts together an exhibit of modern a.pdf
Describe two detection methods for exoplanets other than the.pdf
Case Study WGM employs many employees in several departments.pdf
3 1 point Let PA03PB04PBA01 Find PAB.pdf
Cul de las siguientes describe MEJOR las caractersticas d.pdf
1 How to calculate COGS and Ending Inventory using either t.pdf
PLEASE HELP Refer to the HarrisTodaro migration model As.pdf
prepare a chart Part 1 Stakeholder Register Choose a proj.pdf
1 Explain the role of each of the following in HIV infectio.pdf
1 As you work towards a final transaction name three items.pdf
PERT ve CPM ile ilgili olarak aadaki ifadelerden hangisi dor.pdf
Please write it in C not python .pdf
Mary Lou eitim tasarruf hesabndan 8000 lk bir datm ald v.pdf
If a profit maximizing monopolist operates where P1 and th.pdf
fy1 y2 y3 5 Let Y1Y2 and Y3 be three continuous rando.pdf
On the basis of the financial ratios and benchmarking inform.pdf
Ad

Recently uploaded (20)

PPTX
Introduction to Building Materials
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Hazard Identification & Risk Assessment .pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
Introduction to Building Materials
AI-driven educational solutions for real-life interventions in the Philippine...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
History, Philosophy and sociology of education (1).pptx
Empowerment Technology for Senior High School Guide
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
FORM 1 BIOLOGY MIND MAPS and their schemes
B.Sc. DS Unit 2 Software Engineering.pptx
Indian roads congress 037 - 2012 Flexible pavement
Virtual and Augmented Reality in Current Scenario
Hazard Identification & Risk Assessment .pdf
1_English_Language_Set_2.pdf probationary
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Unit 4 Computer Architecture Multicore Processor.pptx
Ad

Trace the Dining Philosopher problem and write the flow of s.pdf

  • 1. Trace the Dining Philosopher problem and write the flow of states using table below. If philosophers 2, 3 and 5 try to eat. Write the states of all philosophers whenever there is a change in one philosopher state. Semaphore me= 1; /* for mutual exclusion */ Semaphore s[5], all initially 0; /* for synchronization */ pflag[5]: {THINK, HUNGRY, EAT}, initially THINK; /* philosopher flag */ procedure philosopher(i) //starts here { while TRUE do { THINKING; take_chopsticks(i); EATING; drop_chopsticks(i); } } procedure take_chopsticks(i) { P(me); /* critical section */ pflag[i] = HUNGRY; test[i]; V(me); /* end critical section */ P(s[i]) /* Eat if enabled */ } void test(i) /* Let phil[i] eat, if waiting */ { if ( pflag[i] == HUNGRY && pflag[i-1] != EAT && pflag[i+1] != EAT)then { pflag[i] = EAT; V(s[i]) } } void drop_chopsticks(int i) { P(me); /* critical section */ pflag[i]=THINKING; test(i-1); /* Let phil. on left eat if possible */ test(i+1); /* Let phil. on right eat if possible */
  • 2. V(me); /* up critical section */ } Write the change in state of philosophers [T,E,H]. Initially all are in the thinking state [T].