Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Mar 2008 21:45:15 -0600
From:      "Marko, Shaun" <Shaun.Marko@lodgenet.com>
To:        "FreeBSD Hackers" <freebsd-hackers@freebsd.org>
Subject:   libpthread/fork issue
Message-ID:  <87D91DEDB1111C44BBFB9E3E90FF1E6E9553E0@host.lodgenet.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------_=_NextPart_001_01C88005.A893C9B5
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

I'm working on FreeBSD 6.2 and I'm wondering if anybody can help with an
issue I've found using fork and threads. The attached program
demonstrates the problem. In short, if a process creates a thread, joins
the thread, then forks a child process which creates a thread, the
child's attempt to create a thread will cause the program to dump core
with the following error message:
Fatal error 'mutex is on list' at line 540 in file
/usr/src/lib/libpthread/thread/thr_mutex.c (errno =3D 0).

This seems to be true using an SMP or UP kernel.

If you run the attached program with no arguments, the parent process
will not create and join a thread and will not crash. Here is the
output:
[Sherlock]$ ./threadTest
child: born
child: thread created
child: thread joined
parent: child died

If you run the attached program with "-crash", the parent process
creates and joins a thread, causing the error:
[Sherlock]$ ./threadTest -crash
parent: thread created
parent: thread joined
child: born
Fatal error 'mutex is on list' at line 540 in file
/usr/src/lib/libpthread/thread/thr_mutex.c (errno =3D 0)
parent: child died

Here is the backtrace of the resulting core:
#0  0x28097537 in pthread_testcancel () from /lib/libpthread.so.2
[New Thread 0x8053200 (LWP 100163)]
[New Thread 0x8053000 (LWP 100201)]
(gdb) where
#0  0x28097537 in pthread_testcancel () from /lib/libpthread.so.2
#1  0x2808689a in sigaction () from /lib/libpthread.so.2
#2  0x2808088d in pthread_kill () from /lib/libpthread.so.2
#3  0x28080256 in raise () from /lib/libpthread.so.2
#4  0x28159b78 in abort () from /lib/libc.so.6
#5  0x28097c6f in pthread_testcancel () from /lib/libpthread.so.2
#6  0x2808c85f in _pthread_mutex_trylock () from /lib/libpthread.so.2
#7  0x2808d590 in _pthread_mutex_lock () from /lib/libpthread.so.2
#8  0x28083361 in _spinlock () from /lib/libpthread.so.2
#9  0x280f7ddb in _UTF8_init () from /lib/libc.so.6
#10 0x28172940 in _thread_autoinit_dummy_decl_stub () from
/lib/libc.so.6
#11 0x28074200 in ?? ()
#12 0x2804f405 in symlook_obj () from /libexec/ld-elf.so.1
#13 0x280883ff in pthread_attr_init () from /lib/libpthread.so.2
#14 0x280848fd in sigaction () from /lib/libpthread.so.2
#15 0x2808e915 in pthread_mutexattr_init () from /lib/libpthread.so.2
#16 0x28088116 in pthread_create () from /lib/libpthread.so.2
#17 0x08048795 in spawnThread (caller=3D0x80489f0 "child") at
threadTest.c:21
#18 0x08048879 in main (argc=3D2, argv=3D0x17e) at threadTest.c:62

Any help would be greatly appreciated.=20

-Shaun

------_=_NextPart_001_01C88005.A893C9B5
Content-Type: application/octet-stream;
	name="Makefile"
Content-Transfer-Encoding: base64
Content-Description: Makefile
Content-Disposition: attachment;
	filename="Makefile"

UFJPRz10aHJlYWRUZXN0ClNSQ1M9dGhyZWFkVGVzdC5jCk5PX01BTj10Ck5PX09CSj10CkxEQURE
PS1scHRocmVhZAouaW5jbHVkZTxic2QucHJvZy5taz4K

------_=_NextPart_001_01C88005.A893C9B5
Content-Type: application/octet-stream;
	name="threadTest.c"
Content-Transfer-Encoding: base64
Content-Description: threadTest.c
Content-Disposition: attachment;
	filename="threadTest.c"

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPGVycm5vLmg+
CiNpbmNsdWRlIDxwdGhyZWFkLmg+CgpzdGF0aWMgdm9pZCB1c2FnZSh2b2lkKQp7CiAgICBmcHJp
bnRmKHN0ZGVyciwgInVzYWdlOiB0aHJlYWRUZXN0IFstY3Jhc2hdXG4iKTsKICAgIGV4aXQoMSk7
Cn0Kdm9pZCogdGhyZWFkRnVuYyh2b2lkKiBhcmdzKQp7CiAgICBjaGFyICpjYWxsZXIgPSAoY2hh
ciop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kID09IDApCiAgICB7CglwcmludGYoImNoaWxkOiBi
b3JuXG4iKTsKCXJldHVybiBzcGF3blRocmVhZCgiY2hpbGQiKTsKICAgIH0KICAgIGVsc2UKICAg
IHsKCWludCBzdGF0dXM7CglwaWRfdCBwaWQgPSB3YWl0KCZzdGF0dXMpOwoJaWYgKHBpZCA9PSAt
MSkKCXsKCSAgIGZwcmludGYoc3RkZXJyLCAicGFyZW50OiB3YWl0OiAlc1xuIiwgc3RyZXJyb3Io
ZXJybm8pKTsKCSAgIHJldHVybiAxOwoJfQoJcHJpbnRmKCJwYXJlbnQ6IGNoaWxkIGRpZWRcbiIp
OwogICAgfQogICAgcmV0dXJuIDA7Cn0K

------_=_NextPart_001_01C88005.A893C9B5--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87D91DEDB1111C44BBFB9E3E90FF1E6E9553E0>