Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-09-08 15:45:57


From: William Kempf <sirwillard_at_[hidden]>
> --- In boost_at_[hidden], "Greg Colvin" <gcolvin_at_u...> wrote:
> > From: William Kempf <sirwillard_at_m...>
> > I agree that throwing an exception is a much safer interface, and
> > reasonably clean to use. I don't see that this
> >
> > try {
> > mutex::try_lock tlk(mx);
> > cond.wait(tlk, ...);
> > DoSomethingInteresting();
> > } catch (failed_try) {
> > DoSomethingElse();
> > }
> >
> > is any harder to write than this
> >
> > mutex::try_lock tlk(mx);
> > if (tlk)
> > {
> > cond.wait(tlk, ...);
> > DoSomethingInteresting();
> > } else {
> > DoSomethingElse();
> > }
>
> The real issue is performance. Exceptions are expensive, and the
> main reason to use a try lock is to try and eke out the best possible
> performance (there's other reasons, yes). It might be nice to have
> multiple types of try locks, compile time options on behavior, or to
> make use of the nothrow concept of new. We've been down this road
> before, so I don't expect a concesus of opinion on this one yet, but
> I bet we come back to this at some point.

I'm not that sold on the need for try_lock at all, so I'm
not that concerned about performance. Timeouts are another
matter.

Nevertheless, if performance and safety both matter couldn't
we do some like the following?

    mutex::try_lock tlk(mx);
    if (cond.wait(tlk, ...))
    {
      DoSomethingInteresting();
    } else {
      DoSomethingElse();
    }


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