From owner-freebsd-current Tue Oct 20 11:05:57 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA14390 for freebsd-current-outgoing; Tue, 20 Oct 1998 11:05:57 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from ns.tar.com (ns.tar.com [204.95.187.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA14384 for ; Tue, 20 Oct 1998 11:05:52 -0700 (PDT) (envelope-from lists@tar.com) Received: from ppro.tar.com (ppro.tar.com [204.95.187.9]) by ns.tar.com (8.9.1/8.8.7) with SMTP id NAA11025; Tue, 20 Oct 1998 13:05:04 -0500 (CDT) Message-Id: <199810201805.NAA11025@ns.tar.com> From: "Richard Seaman, Jr." To: "Jason Evans" Cc: "current@freebsd.org" Date: Tue, 20 Oct 98 13:05:03 -0500 Reply-To: "Richard Seaman, Jr." X-Mailer: PMMail 1.92 For OS/2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Subject: Re: Another Serious libc_r problem Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, 19 Oct 1998 18:03:22 -0700 (PDT), Jason Evans wrote: >Hmm, your test case is very similar to some code that was causing deadlock >for me. However, I boiled it down to the following code as being the >actual bug. We may be seeing the same thing (but maybe not; I haven't had >time to dig into this all the way). > >Jason I think the problem in your code is that you expect to be able to recursively lock a mutex in the same thread, using the default mutex type. I don't think this is a bug, since the "default" mutex type is implementation defined, if I'm not mistaken. Try the following adjustments to your code: /* -*-mode:c-*- */ #ifndef _REENTRANT # define _REENTRANT #endif #include #include #include #include #include int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind); int main() { pthread_mutex_t mutex; pthread_mutexattr_t attr; int error; pthread_mutexattr_init (&attr); pthread_mutexattr_setkind_np (&attr, MUTEX_TYPE_COUNTING_FAST); error = pthread_mutex_init(&mutex, &attr); pthread_mutexattr_destroy (&attr); if (error) { fprintf(stderr, "Error in pthread_mutex_init(): %s\n", strerror(error)); exit(1); } fprintf(stderr, "About to lock mutex first time.\n"); error = pthread_mutex_lock(&mutex); if (error) { fprintf(stderr, "Error in pthread_mutex_lock(): %s\n", strerror(error)); exit(1); } fprintf(stderr, "About to lock mutex second time; expect deadlock.\n"); error = pthread_mutex_lock(&mutex); if (error) { fprintf(stderr, "Error in pthread_mutex_lock(): %s\n", strerror(error)); exit(1); } fprintf(stderr, "Wow, no deadlock.\n"); error = pthread_mutex_destroy(&mutex); if (error) { fprintf(stderr, "Error in pthread_mutex_destroy(): %s\n", strerror(error)); exit(1); } return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message