Question: Dining Philosophers Problem Solutions using Semaphores: Each philosopher picks up first the fork on the left and then the fork on the right. After the
Dining Philosophers Problem
Solutions using Semaphores:
Each philosopher picks up first the fork on the left and then the fork on the right. After the philosopher is finished eating, the two forks are replaced on the table.
semaphore fork [5] = {1};
int i;
void philosopher (int i){
while (true) {
think();
wait (fork[i]);
wait (fork [(i+1) mod 5]);
eat();
signal(fork [(i+1) mod 5]);
signal(fork[i]); } }
void main() {
parbegin (philosopher (0), philosopher (1), philosopher (2), philosopher (3), philosopher (4)); }
Tasks:
1. Study the dining philosophers problem and understand the sample semaphore solution above. Discuss your outputs with your classmates.
2. What is the difference between mutex and binary semaphore?
3. How many number of maximum philosophers will this problem have?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
