pthread_mutex_trylock return value on recursion

Jeremy Allison jra at samba.org
Tue Jun 28 19:38:33 UTC 2016


On Sun, Jun 26, 2016 at 03:40:05PM +0300, Konstantin Belousov wrote:
> Hi.
> In the lib/tdb/common/mutex.c, the tdb_runtime_check_for_robust_mutexes()
> function, (AFAIU) which tests the implementation of shared robust
> mutexes for suitability, has the following fragment:
> https://github.com/samba-team/samba/blob/master/lib/tdb/common/mutex.c#L928
> 
> 	ret = pthread_mutex_trylock(m);
> 	if (ret != EDEADLK) {
> 
> The preconditions are that the mutex was locked with EOWNERDEAD result,
> so the current thread already owns the m' lock, and the call I cited
> attempts to recursively lock the owned mutex.
> 
> According to POSIX, pthread_mutex_trylock() must always return EBUSY in
> case the lock cannot be granted.
> EDEADLK is only allowed for blocking
> pthread_mutex_lock().  Glibc implementation indeed returns
> EDEADLK for errorcheck mutexes, but this seems to be non-conformant.
> 
> Would you mind to check for both EDEADLK and EBUSY there, or add a
> configure test and select between EBUSY and EDEADLK at compile time ?
> According to the comment, the goal of the check is to distinguish
> whether libpthread is loaded, so either non-zero error checked is good.

Something like the attached ?

What platform are you testing on so we know how you found this ?

Jeremy.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-s3-tdb-On-some-platforms-pthread_mutex_trylock-retur.patch
Type: text/x-diff
Size: 779 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160628/d46cac5c/0001-s3-tdb-On-some-platforms-pthread_mutex_trylock-retur.diff>


More information about the samba-technical mailing list