pthread_mutex_trylock return value on recursion

Konstantin Belousov kostikbel at gmail.com
Sun Jun 26 12:40:05 UTC 2016


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.

Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160626/11ae7696/signature.sig>


More information about the samba-technical mailing list