Boost logo

Boost :

From: jpanzer_at_[hidden]
Date: 2000-08-10 18:03:52


William Kempf wrote:

> --- In boost_at_[hidden], jpanzer_at_n... wrote:
> > jsiek_at_l... wrote:
> >
> > > William Kempf writes:
> > > > I wouldn't attach it to the condition, however. I'd pass the
> > > > predicate into the wait. Thus the condition can be used to
> track
> > > > different criteria.
> > > >
> > > > cond.wait((free1 > 10)(a));
> > >
> > > Why would you want to use the same condition variable with
> different
> > > criteria? (why not just use a different condition variable)
> >
> > Example: Bounded queue. Producer thread adds an item only if
> > the queue size is less than 100, else it waits. Consumer removes
> > an item only if the queue size is greater than 0, else it waits.
> Two
> > different conditions, both of them dependent on the same
> > variable.
> >
> > (Of course the producer also needs to be able to specify a timeout.)
>
> This can be implemented with either one condition using multiple
> criteria or two conditions. There isn't really an example (at least
> that I can think of) where one or the other is the only solution.
> The question is, which is the better solution for the specific
> problem.

Granted, but the question was "why would you want to". I
think the single condition/multiple criteria strategy is natural
for this example, while the multiple condition strategy is harder
to write and understand, albeit perhaps a bit more efficient in
some cases. At least all the solutions I can think of are
more complex...

John Panzer


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