Examples of safe and unsafe systems: thread max needs cur alloc needs left free
T0 10 5 5 3
T1 4 2 2
T2 9 2 7
There's one resource type (tape drives, say) with twelve instances, allocated as shown. The threads have the indicated max possible needs and remaining needs. The system shown above is safe. {T1,T0, T2} is a safe sequence - the threads could finish executing in that order, even if all the threads first request all of their remaining needs. However, suppose that, starting from the situation depicted in the table above, T2 requests and is given one more tape drive. Then the state changes to this one:thread max needs cur alloc needs left free
T0 10 5 5 2
T1 4 2 2
T2 9 3 6
This system is unsafe. If all the threads request their remaining needs, the system will be deadlocked. It will be possible for the OS to give T1 its remaining needs, and possible for T1 to finish and exit. However, after that there will be only 4 tape drives free, and so both T0 and T2 are set up to wait forever.