DPP
-
Upload
ramasubbu-p -
Category
Education
-
view
1.482 -
download
0
description
Transcript of DPP
![Page 1: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/1.jpg)
Dining-Philosophers Problem
![Page 2: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/2.jpg)
Dining-Philosophers Problem The philosophers share a circular table
surrounded by five chairs, each belonging to one philosopher
In the center of table is a bowl of rice, and the table is laid with 5 single chopsticks
From time to time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest to her
When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks
When she is finished eating, she puts down both her chopsticks and starts thinking
![Page 3: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/3.jpg)
Dining-Philosophers Problem
![Page 4: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/4.jpg)
Dining-Philosophers Problem
![Page 5: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/5.jpg)
Dining-Philosophers Problem
Methods to avoid deadlock: Allow at most four philosophers to
be sitting simultaneously Allow a philosopher to pick up her
chopsticks only if both chopsticks are available (pick them up is a critical section)
![Page 6: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/6.jpg)
Problems with Semaphores
signal (mutex) //violate mutual exclusive critical sectionwait (mutex)
wait (mutex) //deadlock occurs critical sectionwait (mutex)
Omitting of wait (mutex) or signal (mutex) (or both)
![Page 7: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/7.jpg)
Solution to Dining Philosophers
![Page 8: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/8.jpg)
Solution to Dining Philosophers
![Page 9: DPP](https://reader035.fdocuments.in/reader035/viewer/2022081721/555a28bad8b42a900d8b4a3b/html5/thumbnails/9.jpg)
Solution to Dining Philosophers
Each philosopher I invokes the operations pickup() and putdown() in the following sequence:
dp.pickup(i) EATdp.putdown(i)