Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-15 11:00:09


Christopher Currie wrote:
> The differences between
>
> {
> scoped_lock l( m );
> }
>
> and
>
> {
> scoped_timed_lock l( m, t );
> }
>
> are much more descriptive me than
>
> {
> scoped_lock( m );
> }
>
> {
> scoped_lock( m, t );
> }

The "unified" timed lock case is

{
    scoped_lock l( m, false );

    if( l.timed_lock( t ) )
    {
        // do stuff
    }
    else
    {
        // what do we do here? presumably either:

        // setup for unbounded wait
        l.lock();
        // do stuff

        // or signal failure
    }
}

The scoped_timed_lock use case also needs to eventually contain an if( l )
statement; you can't do much if you don't know whether your timed lock
succeeded. One might also argue that a separate scoped_timed_lock makes
accidentally omitting the if() statement more likely and harder to spot.

But it's hard to tell without real use cases.


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