mysterious hang in pthread_create

Andriy Gapon avg at icyb.net.ua
Thu Aug 28 20:52:50 UTC 2008


on 28/08/2008 23:29 Andriy Gapon said the following:
> I tracked all calls to functions of _thr_rtld_*lock* family and it seems 
> that the lock in question gets acquired for writing before the above 
> access. The stack:
> #0  _thr_rtld_wlock_acquire (lock=0x8387740) at 
> /system/src/lib/libthr/thread/thr_rtld.c:144
> #1  0x282a6dcc in _rtld_thread_init () from /libexec/ld-elf.so.1
> #2  0x28f91af6 in _thr_rtld_init () at 
> /system/src/lib/libthr/thread/thr_rtld.c:238
> #3  0x28f938db in _thr_setthreaded (threaded=1) at 
> /system/src/lib/libthr/thread/thr_kern.c:56
> #4  0x28f8d208 in _pthread_create (thread=0x831cb90, attr=0x0, 
> start_routine=0x8170ce0 <Thread::starter(void*)>, arg=0x831cb8c)
>     at /system/src/lib/libthr/thread/thr_create.c:64
> #5  0x08170bd8 in Thread::start (this=0x831cb8c) at client/Thread.cpp:41
> #6  0x080abfb4 in HashManager::startup (this=0x831cb60) at HashManager.h:97
> #7  0x0809f4d6 in startup (f=0x827a2c0 <callBack(void*, std::string 
> const&)>, p=0x0) at client/DCPlusPlus.cpp:82
> #8  0x0827a571 in main (argc=1, argv=0xbfbfe844) at linux/wulfor.cc:61

Quick followup: I rebuilt ld-elf.so with debug symbols and it seems that 
at the following place in rtld_lock.c 'flags' variable gets assigned a 
value of five (5):
(gdb) fr 2
#2  0x282a86bf in _rtld_thread_init (pli=0xbfbfe66c) at 
/system/src/libexec/rtld-elf/rtld_lock.c:275
275             flags = thread_mask_set(~0);
(gdb) list
270     {
271             int flags, i;
272             void *locks[RTLD_LOCK_CNT];
273
274             /* disable all locking while this function is running */
275             flags = thread_mask_set(~0);
276
277             if (pli == NULL)
278                     pli = &deflockinfo;
279
...
(gdb) p flags
$10 = 5

Wait, I think I just found something:
(gdb) b rtld_lock.c:143 if mask != 1
Breakpoint 8 at 0x282a8311: file 
/system/src/libexec/rtld-elf/rtld_lock.c, line 143.
(gdb) c
...
(gdb) bt
#0  def_thread_set_flag (mask=4) at 
/system/src/libexec/rtld-elf/rtld_lock.c:143
#1  0x282a83e0 in thread_mask_set (mask=4) at 
/system/src/libexec/rtld-elf/rtld_lock.c:165
#2  0x282a8410 in wlock_acquire (lock=0x282cddb4) at 
/system/src/libexec/rtld-elf/rtld_lock.c:198
#3  0x282a58b2 in dl_iterate_phdr (callback=0x28f84fc0 
<__fixunssfdi+4352>, param=0xbfbfe200) at 
/system/src/libexec/rtld-elf/rtld.c:2103
#4  0x28f8586f in _Unwind_Find_FDE () from /lib/libgcc_s.so.1
#5  0x28f8267c in _Unwind_GetIPInfo () from /lib/libgcc_s.so.1
#6  0x28f833be in _Unwind_GetIPInfo () from /lib/libgcc_s.so.1
#7  0x28f838c0 in _Unwind_RaiseException () from /lib/libgcc_s.so.1
#8  0x28ee045d in __cxa_throw () from /usr/lib/libstdc++.so.6
#9  0x080d60e2 in File (this=0xbfbfe710, aFileName=@0xbfbfe71c, 
access=1, mode=1) at client/File.cpp:227
#10 0x08192d6f in Util::initialize () at client/Util.cpp:102
#11 0x0809f3cc in startup (f=0x827a2c0 <callBack(void*, std::string 
const&)>, p=0x0) at client/DCPlusPlus.cpp:51
#12 0x0827a571 in main (argc=1, argv=0xbfbfe844) at linux/wulfor.cc:61


So can all this be a result of an exception thrown before threads are 
initialized?
Is this something that might already be fixed in HEAD/trunk or in 
RELENG_7? (I seem to vaguely remember something related).

-- 
Andriy Gapon


More information about the freebsd-threads mailing list