From owner-freebsd-threads@FreeBSD.ORG Wed Sep 22 11:59:36 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD3CC16A4CE; Wed, 22 Sep 2004 11:59:35 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 85D9B43D5C; Wed, 22 Sep 2004 11:59:35 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) i8MBxYKi021181; Wed, 22 Sep 2004 07:59:34 -0400 (EDT) Date: Wed, 22 Sep 2004 07:59:34 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Chris Stenton In-Reply-To: <1095840348.23443.14.camel@hawk.gnome.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: threads@freebsd.org cc: freebsd-current@freebsd.org Subject: Re: daemon threads bug with libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2004 11:59:36 -0000 On Wed, 22 Sep 2004, Chris Stenton wrote: > If you create a thread before calling daemon then the next thread you > create after the daemon call will cause the following error from the > libpthread library. daemon() calls fork(). I don't think you can create a threaded program after a fork if you are already threaded. You have to wait to do any threading (including mutexes and stuff) until after the fork. When you call daemon() there is already a thread and perhaps some locks in the library (libc and libpthread). After the fork, the parent exits and the child is left. You are single threaded after the fork (as defined by POSIX), but libpthread and libc have locks that may be locked by threads created before the fork. > Fatal error 'mutex is on list' at line 516 in file > /usr/src/lib/libpthread/thread/thr_mutex.c (errno = 0) > > This error does not occur if you link with -lc_r, linking with -lthr > causes a core dump. -lthr does not look very stable. > > Here is some test code. I am running FreeBSD 5.3-beta > > Please reply directly as I am not on the mailing list -- Dan Eischen