From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 7 14:19:09 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AD4EB1065754 for ; Fri, 7 Mar 2008 14:19:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 92B1F8FC28 for ; Fri, 7 Mar 2008 14:19:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from zion.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by elvis.mu.org (Postfix) with ESMTP id E29651A4D89; Fri, 7 Mar 2008 06:18:37 -0800 (PST) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Fri, 7 Mar 2008 08:26:14 -0500 User-Agent: KMail/1.9.7 References: <87D91DEDB1111C44BBFB9E3E90FF1E6E9553E0@host.lodgenet.com> In-Reply-To: <87D91DEDB1111C44BBFB9E3E90FF1E6E9553E0@host.lodgenet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803070826.14877.jhb@freebsd.org> Cc: "Marko, Shaun" Subject: Re: libpthread/fork issue X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Mar 2008 14:19:09 -0000 On Thursday 06 March 2008 10:45:15 pm Marko, Shaun wrote: > 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 = 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 = 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=0x80489f0 "child") at > threadTest.c:21 > #18 0x08048879 in main (argc=2, argv=0x17e) at threadTest.c:62 > > Any help would be greatly appreciated. POSIX only lets you call exec() from a child process of a multithreaded app. Either fork before creating threads or just create more threads rather than forking. -- John Baldwin