|
Boost : |
From: William Kempf (sirwillard_at_[hidden])
Date: 2000-08-10 16:36:57
--- In boost_at_[hidden], 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)
It's a complexity trade off. A condition variable is a complex
primitive (oxymoron not intentional) that on some platforms exacts a
rather large resource overhead. So you have a choice between
sacrificing speed for resource optimizations or the other way
around. Either method will work for all cases, the only question
remains which is the better approach for a specific case.
Also, as pointed out by others, using multiple condition variables
can lead to deadlock if not carefully coded. The single condition
variable multiple criteria approach is conceptually easier to
code "correctly".
William Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk