Boost logo

Boost Users :

Subject: Re: [Boost-users] owns_lock on lock not on mutex
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2015-10-12 14:01:38


On 10/12/2015 2:04 PM, gast128 wrote:
> Agustín K-ballo Bergé <kaballo86 <at> hotmail.com> writes:
>
>>
>> On 10/12/2015 6:03 AM, gast128 wrote:
>>> there is an owns_lock on the lock type but not on the mutex. This is quite
>>> unhandy. Any reason why?
>>
>> A mutex could never own a lock on itself. The owner of a lock is the one
>> responsible for calling unlock on it.
>>
>> Regards,
>
> Ok I should have expressed myself better: there seems to be no function to
> query a mutex if it is locked (e.g. no 'is_locked').

Knowing whether a mutex is locked is of little use, it does not tell you
whether you own a lock on that mutex. Not to mention that the
information would already be stale by the time it is returned.

> Use case is that I have
> private functions, which must assert that a non recursive mutex is locked.
> The locking is already done in the public part. Why is there no such
> function? Is there a technical reason or just overlooked?

You should reconsider your preconditions, asserting that a mutex is
locked makes little sense. Most likely the precondition you should be
looking for is whether you own a lock on said mutex instead. Here "you"
could be anything (object instance, scope, function call, underlying
thread or execution agent, etc), so the mutex can't tell you that.

Regards,

-- 
Agustín K-ballo Bergé.-
http://talesofcpp.fusionfenix.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net