Mutexes and error checking

Jilles Tjoelker jilles at stack.nl
Sun Jul 21 16:02:34 UTC 2013


On Sun, Jul 21, 2013 at 12:08:36AM -0400, Joe Marcus Clarke wrote:
> On 7/19/13 1:55 AM, Daniel Eischen wrote:
> > It seems Solaris behaves like Linux with PTHREAD_MUTEX_NORMAL
> > and _unlocking_ mutexes owned by other threads (dead or not).
> > Solaris only returns EPERM for PTHREAD_MUTEX_ERRORCHECK
> > mutexes.

> Given that, should we do the same?

According to http://sourceware.org/glibc/wiki/LockElisionGuide, it seems
like glibc wants to change behaviour here. If a mutex is implemented via
some sort of transactional memory, it may not work correctly if the
mutex is used as a semaphore with a different thread unlocking it. In
particular, attempting to commit a transaction via the XEND instruction
will cause a general protection fault if no transaction is in progress.
Adding software checks against these conditions will use up valuable
transactional memory tracking space.

So I think allowing pthread_mutex_unlock() by a different thread would
be a step backwards.

-- 
Jilles Tjoelker


More information about the freebsd-threads mailing list