Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-22 06:54:05


Howard Hinnant wrote:
>
> I don't dislike these helper functions. But I do dislike the idea that
> they should be the only way to construct-and-try or
> construct-with-time. The problem is that we have 3 different types of
> locks, and I want to be able to construct-and-try in a generic-lock
> function:
>
> template <class Lock>
> void
> foo()
> {
> Lock lk(m, try_lock);
> ...
> }
>
> The above code should work for scoped_lock, sharable_lock and
> upgradable_lock.

template<class Lock> void foo()
{
    bool const deferred = false;

    Lock lock( m, deferred );

    if( lock.try_lock() )
    {
        // locked
    }
}

as usual. Clean separation between lock type (scoped/exclusive, shareable,
upgradable) and lock operations (unconditional blocking lock, try lock,
timed lock, unlock).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk