Name
Size
What it
stores
avail
num resources
x
avail[i] is the
number of available and indistinguishable
1
instances of the
resource
Max
num threads
x
max[i][j] is the
maximum number
num
resources
of instances of
resource j that thread i will request
Allocation
num threads
x
allocation[i][j] is the
number
num
resources
of instances of
resource j that have been allocated to thread i
Need
num threads
x
need[i][j] is
the max number of instances
num
resources
of resource j
that thread i still needs to complete its task
notice that
need[i][:] = max[i][:]-allocation[i][:] when
we
don’t
overestimate the amount of resources we need
Table 1:
Variables used in Bankers Algorithm
Question: If a
system has 100s of
resources and thousands of threads, how
scalable are these algorithms and does it
make sense to do a test on every
allocation?
Explain.
Algorithm 1 Algorithm for finding out if
a system is in a safe state
let work = an
array of length num resources
let finish = an
array of length num threads
work =
avail
for each thread
i set finish[i] to false
while there
exists a thread i such that finish[i] == false and need[i][:] ≤ work
do
work = work + allocation[i][:]
finish[i] =
true
end
while
if finish[i] ==
true ∀i then
system is safe
else
deadlock is
possible
end
if
3.3.1
Examples
The following
are different than book examples that will hopefully give you a chance
to
practice with
the bankers algorithm.
Exercise: Is the
state represented by Table 2 safe?
Exercise: Is the
state represented by Table 3 safe?
Exercise: Can we
satisfy a request of <1,3,1> by thread 0 in state represented
by
Table
4?
4