Situation where two (or more) operations need overlapping sets of resources, and neither can complete because they cannot obtain all locks necessary to complete an operation and release their locks.
Deadlock is situation where multiple operations are waiting for same resource(s) while simultananeously holding other resources that other threads holding the desired resources are waiting for.
For example, given resources A,B,C and processes 1,2.
- 1 locks A and B
- 2 locks C
- 2 needs A to finish
- 1 needs C to finish.
Neither 1 or 2 can release resources before finishing. Therefore, deadlock occurred.
The classical solution to all deadlock problems is to always acquire the resources in the same order in all threads or processes.
Reference