Question: Write a Code in C++ that follwing user input The dining-philosophers problem is considered a classic syruchronization problem because it is an example of a

Write a Code in C++ that follwing user input

Write a Code in C++ that follwing user input The dining-philosophers problem

The dining-philosophers problem is considered a classic syruchronization problem because it is an example of a large elass of concurrency-control problems. It is a simple representation of the need to allocate several resources among several processes in a deadlock-free and staryation-frec manner. Consider five philosophers who spend their lives thinking and eating. The philonophers share a circular table surrounded by five chairs, each belonging to one philosopher. In the center of the table is a bori of rice, and the tabie is laid with five single chopsticks. When a philosopher thinks, she does not interact with her eolleagues. From time fo time, a philosopher gets hungry and tries to pick up the two chopstieks that are closest to her (the chopsticks that are between her and her left and right neighbors). A philosopher may pick up only one chopstick at a time. Obviously, she cam lot pick up a chopetick that is already in the hand of a neighbor. When a hungry philosopher has both her chopsticks at the same rime, she eats without releasing her chopsticks. When she is finished eating, ahe puts down both of her chopsticks and starts thinking again. The dining philosophers problem may lead to a deadlock situation and hence some rules have to be framed to avoid the occurrence of deadlock. Sample Input Enter the total no. of phifesophers: 5 How many are hungry: 3 Enter philosopher I position: 2 Enter philosopher 2 position: 4 Enter philosoplees 3 prosifion: 5 Sample Output 1. One can eat at a time. 2. Two can eat at a time 3. Exit Enteryour choice: 1 Allow one philosonher for ent at any fime P3 is gratnted to ent P 3 is waiting PS is waiting P0 is waiting P5 is granted to eat P5 is waiting. P0 is waiting PO is granted to eat PO is waiting 1.One can cat at a fime 2.Two can eat at a time 3. Exit Enter yu ir choice: 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!