Deadlock Detection and Recovery

Detection

Data Structures used:

Available [R]
Request [N] [R]
Allocated [N] [R]
 

Algorithm:

temporary [0..R] = Copy of Available[]
finished [0..N-1] = false
(Mark all processes as unfinished)


Simulate run:
    go on marking processes as finished as you find 
       them unfinished and satisfy the condition of
      Request[] < Available[]
   if a process is marked finished, increment the temporary
      by adding the resources allocated to this process
   At the end, if there are unfinished processes, they are
     all the members of the Deadlock Set

When to invoke the detection algorithm ?

    periodically ?
    when the throughput drops ?
    upon every request that cannot be granted ?
    manually ?

Recovery

    process termination
        which process to select ?
        how many processes ?
    resource preemption
        which resource and which process ?
    what happens to the current state of computation ?
----------------------

What strategy should an OS adopt ?
Prevention? Avoidance?  Detection and Recovery ?
classes of resources -> mixed strategies