Subject: Re: infinite loop in pthread__mutex_spin after call to exit
To: Andrew Doran <ad@netbsd.org>
From: Sverre Froyen <sverre@viewmark.com>
List: current-users
Date: 12/30/2007 10:19:47
On Friday 28 December 2007, Sverre Froyen wrote:
> On Friday 28 December 2007, Andrew Doran wrote:
> > On Fri, Dec 28, 2007 at 05:18:12PM -0700, Sverre Froyen wrote:
> > > I've been attempting to debug why the program /usr/pkg/qt4/bin/qdbus
> > > hangs after its call to exit.

<snip>

> Here is a backtrace from pthread__mutex_spin:
>
> (gdb) bt
> #0  pthread__mutex_spin (ptm=0xbb86dba0, owner=<value optimized out>)
>     at /usr/src/lib/libpthread/pthread_mutex2.c:206
> #1  0xbbb56a63 in pthread__mutex_lock_slow (ptm=0xbb86dba0)
>     at /usr/src/lib/libpthread/pthread_mutex2.c:248
> #2  0xbb83fb8c in __cxa_atexit () from /usr/lib/libc.so.12
> #3  0xbba8f5ee in guardHash () at kernel/qobject.cpp:420
> #4  0xbba92896 in QObjectPrivate::clearGuards (object=0xbb602430)
>     at kernel/qobject.cpp:487
> #5  0xbba94be5 in ~QObject (this=0xbb602430) at kernel/qobject.cpp:799
> #6  0xbb9ec75b in ~QThread (this=0xbb602430) at thread/qthread.cpp:354
> #7  0xbba70485 in ~QProcessManager (this=0xbb602430)
>     at io/qprocess_unix.cpp:270
> #8  0xbba6f0d0 in __tcf_0 ()
>     at ../../include/QtCore/../../src/corelib/global/qglobal.h:1434
> #9  0xbb83fab6 in __cxa_finalize () from /usr/lib/libc.so.12
> #10 0xbb83f962 in exit () from /usr/lib/libc.so.12
> #11 0x08051356 in main (argc=-1080033280, argv=0x11110001) at qdbus.cpp:391

Here's what happens (see the above backtrace):

__cxa_finalize acquires atexit_mutex.  Then, somehow, before __cxa_finalize 
exits, __cxa_atexit is called, which also tries to acquire atexit_mutex.  The 
result is the loop in pthread__mutex_spin.

So, who is at fault?  Is it the destructor code in QT, is it the atexit code 
in libc, or is it the mutex code in libpthread?

Sverre