[475] in Pthreads mailing list archive
Re: Re-entrant?
daemon@ATHENA.MIT.EDU (Christopher Provenzano)
Wed Oct 23 17:48:12 1996
Reply-To: proven@cygnus.com
To: "Larry V. Streepy, Jr." <streepy@healthcare.com>
Cc: "Alex H.K. Wong" <wong@cs.ucla.edu>, pthreads@MIT.EDU
In-Reply-To: Your message of "Tue, 22 Oct 1996 08:08:50 MDT."
<326CD572.28487393@healthcare.com>
Date: Wed, 23 Oct 1996 17:21:30 -0400
From: Christopher Provenzano <proven@proven.org>
> Unfortunately, the POSIX 1003.1 standard says this:
>
> "An atempt by the current owner of a mutex to relock the mutex results
> in undefined behavior."
>
> Sigh.
>
> However, the current version 1.6 Beta 5 release of pthreads provides a
> mutex type MUTEX_TYPE_COUNTING_FAST which allows a single thread to hold
> a mutex multiple times. You must ensure that the thread issues an
> equivalent number of pthread_mutex_locak and pthread_mutex_unlock calls.
> Just remember that if you use it, it's non-standard, and thus
> non-portable.
I suspect recursive mutexes will make it into the extensions for
POSIX 1003.1c standard whenever they get around to it. But that may
be a while from now. For now to use recursive mutexes do the following...
pthread_mutex_t mutex;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEXTYPE_RECURSIVE);
pthread_mutex_init(&mutex, &attr);
The constant MUTEX_TYPE_COUNTING_FAST is internal to pthreads and may
change.
CAP