[asterisk-dev] Lock Debugging Improvements

Russell Bryant russell at digium.com
Wed Aug 1 15:55:36 CDT 2007


Greetings,

After a few discussions with Kevin, I wrote some code to help make debugging deadlocks
easier when we are dealing with problems on a user's machine.

I am posting this here for any feedback on the approach and implementation.  I would
really like to merge this into both 1.4 and trunk, as the code is only enabled in
DEBUG_THREADS mode, and will make retrieving the necessary information for debugging
deadlocks *a lot* easier.

See the following commit for a more detailed description of what it does, as well as the
code itself:

http://lists.digium.com/pipermail/asterisk-commits/2007-August/015106.html


Here is an example of the CLI output of "core show locks" when a deadlock has occurred.


 /* Intentional deadlock to show CLI command output */

static void *lock_test1(void *data)
{
    ast_mutex_lock(&lock1);
    usleep(3000000);
    ast_mutex_lock(&lock2);

    return NULL;
}

static void *lock_test2(void *data)
{
    ast_mutex_lock(&lock2);
    usleep(3000000);
    ast_mutex_lock(&lock1);

    return NULL;
}

*CLI> core show locks

=======================================================================
=== Currently Held Locks ==============================================
=======================================================================
===
=== <file> <line num> <function> <lock name> <lock addr> (times locked)
===
=== Thread ID: 1074006336 (lock_test1 started at [ 1260] utils.c ast_utils_init())
=== ---> Lock #0: utils.c 1234 lock_test1 &lock1 0x724920 (1)
=== ---> Waiting for Lock #1: utils.c 1236 lock_test1 &lock2 0x7247c0 (1)
=== -------------------------------------------------------------------
===
=== Thread ID: 1074272576 (lock_test2 started at [ 1261] utils.c ast_utils_init())
=== ---> Lock #0: utils.c 1243 lock_test2 &lock2 0x7247c0 (1)
=== ---> Waiting for Lock #1: utils.c 1245 lock_test2 &lock1 0x724920 (1)
=== -------------------------------------------------------------------
<snip>

-- 
Russell Bryant
Software Engineer
Digium, Inc.




More information about the asterisk-dev mailing list