Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 May 2012 20:15:26 +0000 (UTC)
From:      jb <jb.1234abcd@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Questions on adaptive mutexes and trylock
Message-ID:  <loom.20120509T213539-939@post.gmane.org>
References:  <4FAA8B8E.2070506@marcuscom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Joe Marcus Clarke <marcus <at> marcuscom.com> writes:

> 
> The newest GLib (as well as PHP APC) is starting to use adaptive mutexes
> in their code.  When a mutex type is set to adaptive and you try to call
> pthread_mutex_trylock() on it, you get back an EINVAL.  Is this a bug,
> or should this really be happening (the code clearly indicates adaptive
> mutexes are not handled by trylock)?

Adaptive mutex is a combination of a mutex and a spinlock with adjusted
duration of spinning ("trylocking").

The primary purpose of a spinlock is to protect portions of the code that
implement other synchronization primitives such as a mutex, etc.

The pthread_mutex_trylock() attempts to acquire a lock on a mutex.

It follows it is proper to deny direct access to (adaptive) mutex by
pthread_mutex_trylock().
 
> I imagine Linux is not doing this since the code doesn't abort on Linux
> as it does on FreeBSD.  Should we be silently allowing trylock to
> perform a no-op on adaptive mutexes, or should we be handling adaptive
> mutexes with trylock?  Thanks.

I do not know why Linux handles it the way it does.

jb





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?loom.20120509T213539-939>