[Date Prev][Date Next]
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 :)
Pierangelo Masarati writes:
> 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.
Can you give an example of some code which needs this?
I can't offhand think of an problem which this would be the right way to
I can think of examples where recursive mutexes are useful - that is,
the current owner may re-lock a mutex (or attempt to do so), and unlock
it as many times as he locked it. We could implement that if you need
it, the default implementation could use a ldap_pvt_thread_cond_t
waiting for a "locked by this thread" condition. Get the thread id with
ldap_pvt_thread_self(), compare with ldap_pvt_thread_equal().
And a trylock function could fail if another thread held the mutex.
>> 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...
Which is what I was doubting would work.
And Kurt already mentioned it won't work with recursive mutexes.