From owner-freebsd-current@FreeBSD.ORG Wed Sep 22 14:29:40 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B834816A4CE; Wed, 22 Sep 2004 14:29:40 +0000 (GMT) Received: from smtp.enta.net (smtp.enta.net [195.74.97.230]) by mx1.FreeBSD.org (Postfix) with ESMTP id 780AF43D39; Wed, 22 Sep 2004 14:29:40 +0000 (GMT) (envelope-from jacs@gnome.co.uk) Received: from hawk.gnome.co.uk (81-31-113-153.adsl.entanet.co.uk [81.31.113.153]) by smtp.enta.net (Postfix) with SMTP id 781A899EFE; Wed, 22 Sep 2004 15:38:33 +0100 (BST) Received: from kite (kite.gnome.co.uk [192.168.123.3]) by hawk.gnome.co.uk (8.13.1/8.12.10) with SMTP id i8METWqa036020; Wed, 22 Sep 2004 15:29:32 +0100 (BST) (envelope-from jacs@gnome.co.uk) Message-ID: <00da01c4a0b0$93b46d60$037ba8c0@gnome.co.uk> From: "Chris Stenton" To: "Daniel Eischen" References: Date: Wed, 22 Sep 2004 15:29:32 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Scanned-By: MIMEDefang 2.44 cc: threads@freebsd.org cc: freebsd-current@freebsd.org Subject: Re: daemon threads bug with libpthread X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2004 14:29:40 -0000 Thanks Dan, As you can see I do a pthread_join before the daemon call so all threads should be closed at that point. There must be some residual state left. Chris ----- Original Message ----- From: "Daniel Eischen" To: "Chris Stenton" Cc: ; Sent: Wednesday, September 22, 2004 12:59 PM Subject: Re: daemon threads bug with libpthread > 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 >