Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1 (to be submitted in the lab) Solution to dinning-philosopher problem is given below. Although this solution guarantees that no two neighbours are eating
Task 1 (to be submitted in the lab) Solution to dinning-philosopher problem is given below. Although this solution guarantees that no two neighbours are eating simultaneously, it nevertheless must be rejected because it could create deadlock. Suppose that all five philosophers become hungry at the same time and each grabs her right chopstick. All the elements of chopstick will now be equal to 0. When each philosopher tries to grab her left chopstick, she will be delayed forever. Several possible remedies to the deadlock problem are replaced by: 1. Allow at most four philosophers to be sitting simultaneously at the table. 2. Allow a philosopher to pick up her chopsticks only if both chopsticks are available (to do this, she must pick them up in a critical section). 3. Use an asymmetric solution-that is, an odd-numbered philosopher picks up first her left chopstick and then her right chopstick, whereas an even numbered philosopher picks up her right chopstick and then her left chopstick. Dinning-philosopher basic solution wait (chopstick[i]); wait (chopstick[ (i+1) % 5]); /* eat for a while */ signal (chopstick[i]); signal (chopstick[(i+1) % 5]); /* think for a while */ Problem: Incorporate all of the three solutions one by one to the basic solution for deadlock free execution of the code. You are required to submit each solution in a separate file. Task 1 (to be submitted in the lab) Solution to dinning-philosopher problem is given below. Although this solution guarantees that no two neighbours are eating simultaneously, it nevertheless must be rejected because it could create deadlock. Suppose that all five philosophers become hungry at the same time and each grabs her right chopstick. All the elements of chopstick will now be equal to 0. When each philosopher tries to grab her left chopstick, she will be delayed forever. Several possible remedies to the deadlock problem are replaced by: 1. Allow at most four philosophers to be sitting simultaneously at the table. 2. Allow a philosopher to pick up her chopsticks only if both chopsticks are available (to do this, she must pick them up in a critical section). 3. Use an asymmetric solution-that is, an odd-numbered philosopher picks up first her left chopstick and then her right chopstick, whereas an even numbered philosopher picks up her right chopstick and then her left chopstick. Dinning-philosopher basic solution wait (chopstick[i]); wait (chopstick[ (i+1) % 5]); /* eat for a while */ signal (chopstick[i]); signal (chopstick[(i+1) % 5]); /* think for a while */ Problem: Incorporate all of the three solutions one by one to the basic solution for deadlock free execution of the code. You are required to submit each solution in a separate file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started