[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: A clean way to detect if a ldap_pvt_thread_mutex is locked (best would be also to know who's the owner of the lock :)

At 12:29 AM 3/29/2006, Pierangelo Masarati wrote:
>I fear yet more few minor concurrency issues in libldap; I'd like to be
>able to assert if a mutex is locked from inside library functions, and it
>would be great to also know who's locking it.
>What I'd do is
>#define ISLOCKED(m) \
>        ( ldap_pvt_mutex_trylock( (m) ) ? 1 \
>                : ( ldap_pvt_mutex_unlock( (m) ), 0 ) )

Note that this can 0 in the case where the current thread
already holds the lock and the underlying thread library
provides reentrant locking; and can return 1 when the
current thread holds the lock and the underlying thread
library doesn't provide reentrant locking.

But as Hallvard asks, what use is this information
given its validity would be void before it could possibly used?

Lastly, if you want to know who has the lock, you need to
build that on-top of the mutexes as most (if not all)
of the threading packages we use do not expose interfaces
report who holds a mutex.


>Ing. Pierangelo Masarati
>Responsabile Open Solution
>OpenLDAP Core Team
>SysNet s.n.c.
>Via Dossi, 8 - 27100 Pavia - ITALIA
>Office:   +39.02.23998309          
>Mobile:   +39.333.4963172
>Email:    pierangelo.masarati@sys-net.it