Intel® Inspector Help

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.

Problem type: Deadlock

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.

Note

  • Deadlock problems are usually, but not always, caused by Lock hierarchy violation problems. If the Intel Inspector detects a Deadlock problem caused by a Lock hierarchy violation problem, it reports only the Deadlock problem.

  • Intel Inspector cannot detect a Deadlock problem involving more than four threads.

C Example

Preparation

CRITICAL_SECTION cs1;
CRITICAL_SECTION cs2;
int x = 0;
int y = 0;
InitializeCriticalSection(&cs1); // Allocation Site (cs1)
InitializeCriticalSection(&cs2); // Allocation Site (cs2)

Thread #1

EnterCriticalSection(&cs1); // Lock Owned (cs1)
x++;
EnterCriticalSection(&cs2); // Lock Wanted (cs2)
y++;
LeaveCriticalSection(&cs2);
LeaveCriticalSection(&cs1);

Thread #2

EnterCriticalSection(&cs2); // Lock Owned (cs2)
y++;
EnterCriticalSection(&cs1); // Lock Wanted (cs1)
x++;
LeaveCriticalSection(&cs1);
LeaveCriticalSection(&cs2);

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:

  1. EnterCriticalSection(&cs1); in thread #1

  2. EnterCriticalSection(&cs2); in thread #2

Fortran Example

Preparation

include "omp_lib.h"
integer(omp_lock_kind) lock1
integer(omp_lock_kind) lock2
call omp_init_lock(lock1)
call omp_init_lock(lock2)

Thread #1

call omp_set_lock(lock1)
. . .
call omp_set_lock(lock2)
. . .
call omp_unset_lock(lock2)
. . .
call omp_unset_lock(lock1)

Thread #2

call omp_set_lock(lock2)
. . .
call omp_set_lock(lock1)
. . .
call omp_unset_lock(lock1)
. . .
call omp_unset_lock(lock2)

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:

  1. call omp_set_lock(lock1) in thread #1

  2. call omp_set_lock(lock2) in thread #2

Possible Correction Strategies