A deadlock is where both threads get stuck waiting on acquiring a lock that the other thread is currently holding. e.g. thread A holds lock X and thread B holds lock Y; thread A requires lock Y to proceed and thread B requires lock X to proceed.
A deadlock can occur if the following conditions are true:
- Mutual Exclusion: existence of critical sections
- Hold and Wait: a thread is currently holding a lock and seeking to acquire others
- No preemption: a lock is only released when the holding thread releases it
- Circular wait: there exists a cycle of threads waiting on each other for locks