[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 :)

On Wed, 2006-03-29 at 22:02 +0200, Hallvard B Furuseth wrote:

> > #define ISLOCKED(m) \
> >         ( ldap_pvt_mutex_trylock( (m) ) ? 1 \
> >                 : ( ldap_pvt_mutex_unlock( (m) ), 0 ) )
> Huh?  That returns true if _some_ thread holds the lock and false
> otherwise - except that the return value may be obsolete by the time it
> is used.

Well, what I really need as a baseline is if some mutex is not locked at
all.  If it's not, then it's an error.  If it is, it's an error only if
it's not owned by the caller.  Right now, I can't detect this case, so
my test won't be exaustive; in any case, if I don't know who's actully
owning it, it is likely that I wouldn't be able to debug it anyway.

> And I don't know if all thread packages behave well if a
> thread attempts to lock a mutex it already owns.

I'll suppose they do; that's what trylock() is intended for...

> If you want a way to ask a mutex if it is locked by the current thread,
> I suppose there are some thread implementations which support that, but
> I don't see it in pthreads.

I don't want to be implementation-dependent (although I mostly need to
do this debugging on Solaris 8).  And I don't want to maintain too much
this type of intrusive instrumenting; I'd like to commit it, as soon as
it's hidden behind some nice wrapping.


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