In: Computer Science
Write a Pthreads program 'Dining-Philosophers.c' to implement the classical 'Dining-Philosophers'problem by using Pthreads mutex locks and condition variables. To implement the program, please followthe hints below.
(a) The detailed 'Dining-Philosophers' problem statement: Refer to Page 71 ~ Page 72 in 'Lecture-08.pptx'
(b) The introduction to Pthreads mutex locks and condition variables: Refer to Page 17 ~ Page 39 in'Lecture-08.pptx'
(c) Creating five philosophers, each of which will run as a separate thread. Philosophers alternatebetween thinking and eating:
The activities of thinking and eating can be simulated by having the thread sleep for a random periodbetween one and three seconds.
When a philosopher wishes to eat, he/she invokes the function: Pickup_Forks (int Philosopher_ID)
When a philosopher finishes eating, he/she invokes the function: Return_Forks (int Philosopher_ID)
There are many possible output sequences. Here is one possible output sequence.
Note: I place the output sequence into two columns here, actually the five on the left column should be placed before the rest five on the right column in the same column.
./Dining-Philosophers
Philosopher 0 is eating | Philosopher 1 is eating |
Philosopher 2 is eating | Philosopher 1 is thinking |
Philosopher 2 is thinking | Philosopher 3 is thinking |
Philosopher 3 is eating | Philosopher 4 is eating |
Philosopher 0 is thinking | Philosopher 4 is thinking |