Deadlock

image.png

  • What causes deadlock?
    • Mutual exclusion: Threads claim exclusive control of resources that they require (e.g., a thread grabs a lock).
    • Hold-and-wait: Threads hold resources allocated to them (e.g., locks that they have already acquired) while waiting for additional resources (e.g., locks that they wish to acquire).
    • No preemption: Resources (e.g., locks) cannot be forcibly removed from threads that are holding them.
    • Circular wait: There exists a circular chain of threads such that each thread holds one or more resources (e.g., locks) that are being requested by the next thread in the chain.
  • How to avoid deadlocks
    • Circular Wait
    • Hold and Wait
  • What to do when deadlock happens
    • Kill
    • wait for resources