Deadlock

There are four conditions that are necessary for a deadlock to exist. If even one of these conditions isn't true, there is no deadlock:

  1. Mutual Exclusion: At least one resource is held in a non-sharable mode by some process/thread. If any other process requests this resource, then this 2nd process must wait for the resource to be released by the holder.
  2. Hold and Wait: A process must be simultaneously holding at least one resource and waiting for at least one resource that is currently being held by some other process.
  3. No preemption: Once a process is holding a resource (i.e. once its request has been granted), that resource cannot be taken away from that process until the process voluntarily releases it. In other words, the OS won't forcefully take a resource held by any process from it.
  4. Circular Wait: There exists a group of processes that are waiting for each other's resources. Mathematically, the group of processes is {P0, P1, P2, ..., PN}, and each process Pi is waiting for the resource that Pi+1 holds. (Note: Circular Wait implies that Hold and Wait is true, but it is easier to consider the four conditions separately.)