Deadlocks have a few conditions:

  • Mutual exclusion
  • Hold and wait (you have a lock and try to acquire another)
  • No pre-emption (we can’t take locks away)
  • Circular wait (waiting for a lock held by another process)

How do we prevent deadlocks?

  • Ensure order of locks (i.e., we acquire locks one after the other, then unlock in the opposite order).
  • Could use trylock