Method for Handling Deadlocks

In order for a deadlock to occur, you must have all four of the following conditions met:

  1. Mutual Exclusion.
  2. Hold and Wait: Processes already holding a resource can request additional resources, without relinquishing their current resources.
  3. No preemption: One process cannot forcibly remove another process’ resource.
  4. Circular wait.

Most deadlock prevention algorithms focus on avoiding condition #4: circular wait.

Deadlock Prevention:

– Disallow one of the four necessary conditions for deadlock

Deadlock Avoidance:

– Do not grant a resource request if this allocation have the potential to lead to a deadlock

Deadlock Prevention:

  • Mutual Exclusion
    • Not here
  • Hold and wait
    • No wait, require a thread to request and be allocated all its resources before it begins execution, or it can only request resources when it has none
  • No preemption
    • If a thread is holding some resources and requesting a resource that is held, then all resources currently being held are released. But need to save the state of preempted resources.
  • Circular wait
    • Locks (resources) are assigned numerical values, and threads must only acquired locks that have higher numbers than locks that have already acquired.
    • Let different threads acquire resources in the same order.