|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2005-08-29 19:42:12
Hello,
I have the following scenario:
Evaluate String Stream until a certain string is found or a time has occured. The string
evaluation is made not in a single function, but using a stream iterator and later an evaluator of
the retrieved data.
I have an iterator class as function object where a
boost::shared_ptr<boost::timed_mutex> mutex;
member is defined. It has 2 functions:
operator()() which is a worker function of the time_out thread and an iteratorion function.
Now I start when entered for the first time the iteration function the time_out thread. The
time_out thread should block until the time_out elapses or the another function has found the
desired string from the stream.
my code looks like:
operator()()
{
boost::timed_mutex::scoped_timed_lock lock(*mutex, true);
boost::condition c;
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec +=20;
c.timed_wait(lock, xt);
}
My approach was to use the mutex object for syncronization. I assumed that it is locked as long as
c.timed_wait(...) is waiting.
So I try to lock this object in the other thread. If the mutex object can not be locked the worker
thread is still waiting, otherwise time_out elapsed.
>From the Rationale section of the thread docs I heavily understand which locking strategy is used
for timed_mutex. Can someone point me to a the correct place with documentation and say if this
approach will work or I should consider a redesign?
With Kind Regards,
Ovanes Markarian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net