apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel May <Dan...@spryware.com>
Subject RE: Posix sems still not recommended?
Date Wed, 08 Apr 2009 01:38:25 GMT
I have spent a considerable amount of time on this in the past few weeks, so let me elaborate
on what I have found.

1. A few years ago, we implemented our own inter-process, shared mutex.  We did this using
a pthread_mutex and storing the pthread_mutex_t in shared memory, setting the PTHREAD_PROCESS_SHARED
attribute.  To overcome the problem where the owner of the mutex dies, we also store the pid
of the current owner in the same shared memory segment along with the pthread_mutex_t, and
try to detect dead owners and transfer ownership.

2. We recently discovered a race condition where the creation and destruction of the mutex
was not atomic, between the creation of the shared memory and initialization of the pthread_mutex_t,
there was a race condition.  We solved this by using a binary semaphore (sem_open(), etc.)
to protect the creation and deletion.

3. We considered simply using the binary semaphore as a replacement for the inter-process
pthread_mutex, but it was more than an order of magnitude slower and did not natively support

4. The MAC OSX implementation of pthreads does not support PTHREAD_PROCESS_SHARED, so we still
do not have a favorable solution for OSX.

5. In reviewing the latest pthreads source code for RH Linux, it appears that the "robust"
implementation handles the abandon problem much smoother, but this implementation is still
rather new.


-----Original Message-----
From: Rainer Jung [mailto:rainer.jung@kippdata.de] 
Sent: Tuesday, March 31, 2009 2:00 AM
To: APR Development List
Subject: Re: Posix sems still not recommended?

On 30.03.2009 20:58, Jeff Trawick wrote:
> On Mon, Mar 30, 2009 at 2:33 PM, Jeff Trawick <trawick@gmail.com
> <mailto:trawick@gmail.com>> wrote:
> On Mon, Mar 30, 2009 at 2:07 PM, Jim Jagielski <jim@jagunet.com
> <mailto:jim@jagunet.com>> wrote:
> Anyone know if:
> # POSIX semaphores and cross-process pthread mutexes are not # used
> by default since they have less desirable behaviour when # e.g. a
> process holding the mutex segfaults.
> is still applicable, at least for posix sems?
> AFAIK, the Solaris-specific recovery logic for cross-process pthread
> mutexes has been working reliably for a long time, but with the
> current wind direction APR is choosing fcntl(), which has sysdef
> implementations on that
> ugh; "sysdef implications"

and quite often shows EDEADLOCK, even when you can prove there can't be
one. Especially when starting to use more than one lock of that type
(e.g. when SSL comes into the game).

> platform.
> no clues here about the POSIX semaphores

I would be much interested in an answer as well. Because of the
EDEADLOCK problems I did suggest using the pthread based mutex on
Solaris for a while to people and got no problem reports. But what
experience do others have?

In a related thread on the Tomcat users list about mod_jk I wrote in

   I now did some searching and it turns out that the implementation of
   pthread mutexes for Solaris 10 has very recently changed quite a bit.
   So all speculations about improved pthread mutex behaviour
   (especially for "robust" mutexes) in the last years might have become

   The new implementation is contained in Solaris kernel patch 137137-09
   and most likely also in Solaris 10 Update 6 (10/08). I didn't check,
   whether that update simply contains the kernel patch or the fix is
   included independently.

   Some detail is logged in Sunsolve under the bug IDs

   6296770 2160259 6664275 6697344 6729759 6564706



View raw message