From owner-freebsd-threads@FreeBSD.ORG Wed Sep 22 08:05:54 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 3C83A16A4CE; Wed, 22 Sep 2004 08:05:54 +0000 (GMT) Received: from smtp.enta.net (smtp.enta.net [195.74.97.230]) by mx1.FreeBSD.org (Postfix) with ESMTP id EC0D443D2D; Wed, 22 Sep 2004 08:05:53 +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 4D33299F3C; Wed, 22 Sep 2004 09:14:45 +0100 (BST) Received: from [192.168.123.12] (hawk.gnome.co.uk [192.168.123.12]) by hawk.gnome.co.uk (8.13.1/8.12.10) with ESMTP id i8M85mKn023670; Wed, 22 Sep 2004 09:05:48 +0100 (BST) (envelope-from jacs@gnome.co.uk) From: Chris Stenton To: freebsd-current@freebsd.org Content-Type: text/plain Message-Id: <1095840348.23443.14.camel@hawk.gnome.co.uk> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Wed, 22 Sep 2004 09:05:48 +0100 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.44 cc: threads@freebsd.org Subject: daemon threads bug with libpthread X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2004 08:05:54 -0000 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. 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 Thanks Chris #include #include #include #include void *slave (void *args); void *slave2 (void *args); typedef struct { int data; pthread_mutex_t *mut; } simple; simple status; int main () { pthread_t sla, sla2; pthread_create (&sla, NULL, slave, &status); pthread_join(sla, NULL); daemon(0,1); pthread_create (&sla2, NULL, slave2, &status); for(;;){ } return 0; } void *slave (void *arg) { simple *status; status = (simple *)arg; pthread_mutex_lock (status->mut); status->data++; usleep(500000); printf("******slave me me me %d *********** \n",status->data ); pthread_mutex_unlock (status->mut); return (NULL); } void *slave2 (void *arg) { simple *status; status = (simple *)arg; for(; /* ever */ ;) { pthread_mutex_lock (status->mut); status->data++; usleep(500000); printf("******slave2 me me me %d \n",status->data ); pthread_mutex_unlock (status->mut); } return (NULL); }