The main complexity of the banker's algorithm in this exercise lies within the checksafe()
function, which is called during a request of resources through requestResources()
by some process.
The first section initializes the temporary arrays that the algorithm will use to check the new state of system, which are temp_avail[]
, temp_need[][]
, temp_allocation[][]
, work[]
, and finally finish[]
which is used to verify that each individual process is will not cause a deadlock in this new state. Given
assuming the assignment operation is
In the final section that carries out the actual safety check, a while loop is used to iterate a single for-loop of checkSafe()
returns true
). This for-loop also contains a comparison operation which compares two different arrays of
*Formula ignores some simple $\mathcal{O}(1)$ assignment and comparison operations.