```7. 19 Answer: Consider a system with resources A, B, and C and processes
P0, P1, P2, P3, and P4 with the following values of Allocation:
Allocation
ABC
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
ABC
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, ifwe treat the three resources as three single-resource types
of the banker’s algorithm, we get the following:
For resource A(of which we have 2 available),
Allocated Need
P0 0 7
P1 3 0
P2 3 6
P3 2 0
P4 0 4
Processes could safely finish in the order P1, P3, P4, P2, P0.
For resource B (of 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 P2, P3, P1, P0, P4.
And finally, for For resource C (of which we have 0 available),
Allocated Need
P0 0 3
P1 2 0
P2 2 0
P3 1 1
P4 2 1
Processes could safely finish in the order P1, P2, 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 P0 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.
a. What is the content of the matrix Need? The values of Need for
processes P0 through P4 respectively are (0, 0, 0, 0), (0, 7, 5, 0), (1,
0, 0, 2), (0, 0, 2, 0), and (0, 6, 4, 2).
b. Is the system in a safe state? Yes. With Available being equal to (1,
5, 2, 0), either process P0 or P3 could run. Once process P3 runs, it
releases its resources, which allow all other existing processes to
run.
c. If a request from process P1 arrives for (0,4,2,0), can the request
be granted immediately? Yes, it can. This results in the value of
Available being (1, 1, 0, 0). One ordering of processes that can finish
is P0, P2, P3, P1, and P4.
7.22
semaphore ok to cross = 1;
void enter bridge() {
ok to cross.wait();
}
void exit bridge() {
ok to cross.signal();
}
```