Answer for Homework 5

 

Task1: Deadlock Avoidance

Process Current Allocation Maximum Allocation Available Need
  A B C D A B C D A B C D A B C D
P1 0 1 2 0 0 1 2 0 4 2 0 1 0 0 0 0
P2 1 0 0 1 7 5 0 1   6 5 0 0
P3 3 5 4 1 3 5 6 2   0 0 2 1
P4 6 3 2 0 6 5 2 0   0 2 0 0
P5 0 1 4 0 6 5 6 0   6 4 2 0

a)Draw a resource allocation graph for the snapshot of the system

Please reference page 211 of textbook.

for example, P2 is holding one instance of B ,one instance of D and waiting for six instances of A, five instances of B. The figure is as the following:

b)Please reference 7.5.3.1 safety algorithm

Work=Work+Current Allocation

Step is point to the algorithm.

step Process Current Allocation Maximum Allocation Need Aviable(work)
    A B C D A B C D A B C D A B C D
          4 2 0 1
2,3 P1 0 1 2 0 0 1 2 0 0 0 0 0 4 3 2 1
2,3 P3 3 5 4 1 3 5 6 2 0 0 2 1 7 8 6 2
2,3 P4 6 3 2 0 6 5 2 0 0 2 0 0 13 11 8 3
2,3 P2 1 0 0 1 7 5 0 1 6 5 0 0 14 11 8 3
2,3 P5 0 1 4 0 6 5 6 0 6 4 2 0 14 12 12 3

We can satisfy the requirement of every process, so it's a safe state.

c)Please reference 7.5.3.2 Resource-request algorithm

We can have the two answers:(either of them is right)

(1)If we assume the maximum allocation of P1 is 0120, we get

request[i]>Need[i]

So we will raise a condition error and the request can't be granted.

(2)If we assume the maximum allocation of P1 is 0120+4200=4320, we need to check whether this allocation is safe.

step Process Current Allocation Maximum Allocation Need Aviable(work)
    A B C D A B C D A B C D A B C D
          4 2 0 1
2,3 P1 0 1 2 0 4 3 2 0 4 2 0 0 4 3 2 1
2,3 P3 3 5 4 1 3 5 6 2 0 0 2 1 7 8 6 2
2,3 P4 6 3 2 0 6 5 2 0 0 2 0 0 13 11 8 3
2,3 P2 1 0 0 1 7 5 0 1 6 5 0 0 14 11 8 3
2,3 P5 0 1 4 0 6 5 6 0 6 4 2 0 14 12 12 3

So if we change the maximum allocation of P1, we can satisfy the request immediately.