Pierangelo Masarati writes: > 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 ) )
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. And I don't know if all thread packages behave well if a thread attempts to lock a mutex it already owns. 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. -- Hallvard