Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-10-11 17:07:10


> --- In boost_at_y..., "George A. Heintzelman" <georgeh_at_a...> wrote:
> Looking at your code it appears that you've misused the condition
> type (though I may be wrong since I can't see all of your code).
> Taking your description the whole process should be something more
> like this (poor implementation, but written this way for clarity of
> the concept):
>
> // in parent thread when it terminates...
> {
> boost::mutex::scoped_lock lock(child->mutex);
> child->teminate = true;
> }
>
> // in child thread...
> {
> boost::mutex::scoped_lock lock
> boost::xtime xt;
> xtime_get(&xt, boost::TIME_UTC);
> xt.sec += transmission_delay;
> while (!terminate) {
> if (!cond.timed_wait(lock, xt))
> break;
> }
> if (terminate)
> // handle termination here
> }
> // other processing here
>

Well, this wouldn't quite be what I wanted to do, though I had missed
the point that timed_wait returns whether it timed out or not, which
does simplify things somewhat.

In any case, the code you wrote illustrates my question better. The
documentation of timed_wait says that the lock parameter must fulfill
the ScopedTimedLock model, which boost::mutex::scoped_lock doesn't (I
don't think). My question is, is this an error in the documentation, or
is it really needed for some reason I don't see? In other words, would
the code you wrote above work? If not, it might be worth adding a note
as to why boost::timed_mutex::scoped_timed_lock would be needed...

George Heintzelman
georgeh_at_[hidden]


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