Safety Algorithm


A method used to determine if a particular state is safe.   It's safe if there exists a sequence of processes such that for all the processes, there’s a way to avoid deadlock:
The algorithm uses these variables:

Need[I] – the remaining resource needs of each process.
Work    - Temporary variable – how many of the resource are currently available.
Finish[I] – flag for each process showing we’ve analyzed that process or not.
need <=  available + allocated[0] + .. + allocated[I-1]  ß Sign of success

Let   work   and   finish  be vectors of length m and n respectively.