Philosophers P[0], P[1], P[2], P[3], and P[4] sit at a circular table.
For i=1,2,3,4, Philosopher P[i] uses two forks, Fork[i-1] and Fork[i]. Fork[i-1] is to his right and Fork[i] is to his left.
Philosopher P[0] uses fork Fork[4] (to his right) and Fork[0] (to his left).
Each philosopher needs only two of the forks, but must follow this protocol:
Philosophers 0 - 3 are told: get your left fork first.
Philospher 4 is told: get your right fork first.
Explain why deadlock cannot occur with this protocol.
If resources are "ordered" and processes needing more than one resource are required to request the resources they need in the order they occur in this given ordering, then circular wait cannot occur. Since circular wait is a necessary condition for deadlock, this means that deadlock cannot occur. The protocol given results from ordering the forks in this order: (*) Fork[3], Fork[2], Fork[1], Fork[0], Fork[4] For example, P[1] uses Fork[0] (right) and Fork[1] (left). This ordering requires P[1] to get the right fork, Fork[1], first, since Fork[1] comes before Fork[0] in the order (*) above. Similarly P[0] uses Fork[4] (right) and Fork[0] (left). This ordering requires P[0] to get the left fork, Fork[0], first, since Fork[0] comes earlier than Fork[4] in the orderint (*).
Consider the following snapshot of a system with five processes, P0, P1, P2, P3, and P4 sharing resources of type A, B, C, and D:
Allocation Request Available A B C D A B C D A B C D P0 0 1 1 0 3 1 0 0 2 0 0 0 P1 0 0 0 1 no request P2 0 1 0 0 2 0 1 1 P3 0 0 1 0 no request P4 1 1 0 0 2 1 2 0
Which processes, if any, are deadlocked? Explain.
To determine if deadlock has occurred, try to find an
execution sequence that would allow all processes to finish
provided no additional requests are made other than those
already pending.
Resources Returned After this process Available
finishes A B C D
A B C D 2 0 0 0
0 0 0 1 P1 2 0 0 1
0 0 1 0 P3 2 0 1 1
0 1 0 0 P2 2 1 1 1
No more processes could execute even with the resources A B C D
that would be available after P1, P3, and P2 were finished.
So deadlock has occurred and the deadlock set is { P0, P4}.
Three processes will be executed concurrently. Each of these processes requires from 0 to 4 units of resource A. (These units are interchangeable, so it doesn't matter which particular units of A each process gets.) If a process requests unit(s) of A, the allocation protocol is
What is the minimum number of units of A that can be in the system, so that deadlock will never occur for these three processes. Assume that no other processes use the units of A.
The largest number of units in the system for which deadlock could
still occur corresponds to the state that all all the resources
are allocated, but no process has its maximum. That is, available
should be 0 and each process should have exactly 1 less than its maximum.
That is, each of the 3 proccesses would hold (4-1) = 3 units of A for
a total of 9 units. Since this is the largest number of units
of A for which deadlock could occur, the minimum number of
units of A for which deadlock would never occur is just 1 more:
10 units of A.