Deadlock Avoidance and Prevention in OS

Deadlock Prevention

For deadlock to occur, all of the following condition must be true

  • Mutual exclusion
  • Hold And Wait
  • No Pre emption
  • Circular wait

Hence , the way to prevent deadlock is to ensure that at least one of these conditions do not hold :

  • Mutual exclusion – If 1 resource is non- shareable , then mutual exclusion condition must hold. We can’t prevent deadlock by denying this mutual exclusion condition, as some resource are inherently non shareable and this can’t be changed.
  • Hold And wait – For Hold and wait condition to never occur, it should be made sure that whenever a process requests a resource, it does not hold any other resource.There can be many protocols implemented –
    • One protocol could be Allocating all resources to a process before its execution .
    • Other Could be , A process can request resource only when it has no resource.

Both these suffer from

  • Low resource utilization
  • Starvation
  • No Preemption of resources-  Allow preemption of resources from process when resources are acquired by high priority process.
  • Circular wait – To prevent this, impose a total ordering of all resources types and every process should request resource in increasing order.

Deadlock Avoidance

Deadlock prevention causes low device utilization and reduced system throughput.

To avoid deadlocks, one requires additional information about how resources all to be requested.

  • For one instance of each resource type, Resource Allocation Graph Algorithm is used.
  • For avoidance of multiple instances of each resource type, Banker’s Algorithm is used.

Learn Banker’s Algorithm from this page here.

Please Login/Signup to comment