首页 > 试题广场 >

We can obtain the banker's alg

[问答题]
We can obtain the banker's algorithm for a single resource type from the general banker's algorithm simply by reducing the dimensionality of the various arrays by 1. Show through an example that the multiple-resource-type banker's scheme cannot be implemented by individual application of the single-resource-type scheme to each resource type.
.
推荐
Consider a system with resources A, B, and C and processes P0, P1, P2, P3, and P4 with the following values of Allocation:



Allocation

A
B
C
P0
0
1
0
P1
3
0
2
P2
3
0
2
P3
2
1
1
P4
0
0
2

And the following value of Need:
Need

A
B
C
P0
7
4
3
P1
0
2
0
P2
6
0
0
P3
0
1
1
P4
4
3
1

If the value of Available is (2 3 0), we can see that a request from process P0 for (0 2 0) cannot be satisfied as this lowers Available to (2 1 0) and no process could safely finish.
However, if we were to treat the three resources as three single-resource types of the banker's algorithm, we get the following:
For resource A (which we have 2 available),

Allocated
Need
P0
3
2
P1
0
2
P2
0
0
P3
1
1
P4
0
3

Processes could safely finish in the order of P1,P3,P4,P2, P0.
For resource B (which we now have 1 available as 2 were assumed assigned to process P0),

Allocated
Need
P0
3
2
p1
0
2
p2
0
0
p3
1
1
p4
0
3


Processes could safely finish in the order of P2, P3, P1, P0, P4.
And finally, for For resource C (which we have O available),

Allocated Need
Need
P0
0
3
P1
2
0
P2
2
0
P3
1
1
P4
2
1


Processes could safely finish in the order of P1, , P0, P3, P4.
As we can see, if we use the banker's algorithm for multiple resource types, the request for resources (0 2 0) from process PO is denied as it
leaves the system in an unsafe state. However, if we consider the banker 's algorithm for the three separate resources where we use a single resource type, the request is granted. Therefore, if we have multiple resource types, we must use the banker's algorithm for multiple resource types
发表于 2018-03-23 22:06:52 回复(0)