Deadlock occurs when two or more threads or processes become permanently stuck, each waiting for the other to release a shared resource like a lock or mutex, preventing any of them from progressing.
Deadlock is a common concurrency bug that arises when threads or processes enter a circular waiting pattern. For example, Thread A holds Lock 1 and waits for Lock 2, while Thread B holds Lock 2 and waits for Lock 1. Since neither can proceed without the resource the other holds, the entire system grinds to a halt. This often stems from inconsistent or poorly managed locking order across different parts of the code. To prevent deadlocks, developers should enforce a strict, global order for acquiring multiple locks and use timeouts or non-blocking lock attempts. Techniques like lock hierarchies, deadlock detection algorithms, and minimizing the scope and duration of locks are crucial. Understanding and managing these dependencies is essential for building robust, multi-threaded applications that avoid this silent failure state.
Impact: DoS: Resource Consumption (CPU)DoS: Resource Consumption (Other)DoS: Crash, Exit, or Restart
Each thread of execution will "hang" and prevent tasks from completing. In some cases, CPU consumption may occur if a lock check occurs in a tight loop.