Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 5 1. The story of dining philosophers is described in section 2.5.1.

ID: 3604907 • Letter: A

Question

Assignment 5 1. The story of dining philosophers is described in section 2.5.1. With S philosophers sharing the chopsticks, there is possibility that each philosopher is holding one chopstick and waiting for another one, i.e. a deadlock may occur. The following three solutions solve the deadlock problem: Allow at most four philosophers to be sitting simultaneously at the table. Allow a philosopher to pick up her chopsticks only if both chopsticks are available. a. b. c. se asymmetric pick-up order. i.e. philosophers with odd numbers pick up her left chopsticks first and philosophers with even numbers pick up her right chopsticks irst. Explain that why the above three approaches are deadlock-free.

Explanation / Answer

     If there are 5 philosophers then there will be 5 chopsticks available.

     Now if the 5 philosophers are holding 1 chopstick and waiting for

     other then dead lock will occur and it will be as below.

            P1 ----> P2 ----> P3 ----> P4 ----> P5 ----> P1

   a)

        Now if we allow only 4 or less philosophers then even

        if all 4 philosophers are holding 1 chopstick and waiting for

        other (4 chopsticks are holded), then 1 chopstick will be

        availbe out of 5, adding this 1 chopstick 1 philosopher out of 5

        can eat and leave the 2 chopsticks after his meal and

        hence there will be no deadlock.

b)

        This situation will be equivalent to hold and wait in

        deadlock prevention strategy.

        There we insist that any process holding some resources

        and waiting for other, has to release the holding resources

        and only when all the resources are availble then it has to

        take all the resources.

        Here also we are insisting that only when 2 chopsticks are

        available then only pick. Now out of all 5 philosopher only

        one can eat and after his meal he will left the chopsticks

        so that rest can use and hence there will be no deadlock.

c)

P1 ----> L - R

                 P2 ----> R - L

                 P3 ----> L - R

                 P4 ----> R - L

                 P5 ----> L - R

   Here odd numberd philosophers will not depend on even numberd

philosophers and hence we cannot expect a circular dependency like       

  P1 ----> P2 ----> P3 ----> P4 ----> P5 ----> P1

Hence there will be no deadlock.