Question: Write a program to solve the dining philosophers problem. Dining philosophers is a classic synchronization problem. Five silent philosophers sit around a table with a
Write a program to solve the dining philosophers problem. Dining philosophers is a classic synchronization problem. Five silent philosophers sit around a table with a bowl of rice. A chopstick is placed between each pair of adjacent philosophers. Each philosopher must alternately think and eat. Eating is not limited by the amount of rice left: assume an infinite supply. However, a philosopher can only eat while holding both the chopstick to the left and the chopstick to the right. Each philosopher can pick up an adjacent chopstick, when available, and put it down when holding it. These are separate actions: chopsticks must be picked up and put down one by one. The problem is how to design a discipline of behavior such that each philosopher won't starve, i.e. can forever continue to alternate between eating and thinking.
Please do It in C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
