|
Boost : |
From: William Kempf (williamkempf_at_[hidden])
Date: 2002-10-18 06:54:56
>From: Jonathan Biggar <jon_at_[hidden]>
>David Abrahams wrote:
> > > Although you could have a version of wait that takes another template
> > > "action" functor, and call it like this:
> > >
> > > cond.wait(predicate, action);
> > >
> > > and encapsulate the loop entirely.
> >
> > I don't see what you're getting at here. The loop is already entirely
> > encapsulated in the current version. What's action supposed to do?
>
>Sorry, I meant encapsulating the loop *and* the locking, so it would be
>equivalent to:
>
> lock->acquire();
> while (!predicate())
> cond.wait();
> action();
> lock->release();
As yet another alternative, possibly, but not as a replacement. If the
above were encapsulated into the wait(pred, act) function, the action
function object would be difficult to construct in many cases since it would
require access to data outside of the current scope (i.e. a closure). This
will occur more frequently with the action then with the predicate, btw.
Dave, this answers why we have a non-predicated version as well. Without a
very elaborate lambda library (which isn't available on all compilers, and
with out language support is still complex enough to be confusing and
difficult to use for some users, etc.) there are many use cases where the
predicate version puts a very high burden on the developer, where the
non-predicated version, though easier to misuse, is by far easier to code.
More rationale, and possibly a lessening of the emphasis on the "danger" of
using the non-predicate version.
As for locking the unlocked mutex in the wait... I'll have to ponder that
one some. It hadn't occured to me to do that since it would be wrong to do
so in the non-predicated version. For consistency, I'd probably reject this
idea, but I should be fair and evaluate all the pros/cons of this.
Bill Kempf
_________________________________________________________________
Get faster connections -- switch to MSN Internet Access!
http://resourcecenter.msn.com/access/plans/default.asp
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk