Deadlock
Occurs when two or more threads are waiting for each other to release resources (such as mutexes, critical sections, and thread handles) while holding resources the other threads are trying to acquire. If none of the threads release their resources, then none of the threads can proceed.

ID | Code Location | Description |
---|---|---|
1 | Allocation site | If present, represents the location and associated call stack where the resource was created. |
2 | Lock owned | Represents the location and associated call stack of the thread holding the object requested by another thread. |
3 | Lock wanted | Represents the location and associated call stack of the thread requesting the object held by another thread. |
- Deadlockproblems are usually, but not always, caused byLock hierarchy violationproblems. If theIntel Inspectordetects aDeadlockproblem caused by aLock hierarchy violationproblem, it reports only theDeadlockproblem.
- Intel Inspectorcannot detect aDeadlockproblem involving more than four threads.
C Example
Preparation |
|
Thread #1 |
|
Thread #2 |
|
If thread #1 and thread #2 are concurrent and there is no other synchronization between them, the
Intel Inspector
detects a Deadlock
problem if synchronization occurs in the following order: - EnterCriticalSection(&cs1);in thread #1
- EnterCriticalSection(&cs2);in thread #2
Fortran Example
Preparation |
|
Thread #1 |
|
Thread #2 |
|
If thread #1 and thread #2 are concurrent and there is no other synchronization between them, the
Intel Inspector
detects a Deadlock
problem if synchronization occurs in the following order: - call omp_set_lock(lock1)in thread #1
- call omp_set_lock(lock2)in thread #2
Possible Correction Strategies
- Do not use multiple synchronization objects if one synchronization object is sufficient.
- Use recursive synchronization objects such as recursive mutexes if a thread must acquire the same object more than once.
- Avoid the case where two threads wait for each other to terminate. Instead, use a third thread to wait for both threads to terminate.
- Establish a global lock hierarchy and honor the same lock hierarchy in each thread. For example:
- C language: If you have critical sectionscs1andcs2and establish a global lock hierarchy (cs1,cs2), always acquirecs1before acquiringcs2and releasecs1after releasingcs2.
- Fortran language: If you have lockslock1andlock2and establish a global lock hierarchy (lock1,lock2), always acquirelock1before acquiringlock2and releaselock1after releasinglock2.
- C language: Consider acquiring multiple synchronization objects at the same time using, for example, Microsoft Windows* system APIs such asWaitForMultipleObjects().