|
Boost Users : |
From: Christian Henning (chhenning_at_[hidden])
Date: 2005-08-10 09:31:52
Thanks for the answer. Here is more better code sample. The _oThread
object is RAII object that makes sure the boost::thread::join() is
called when the object is destructed.
fvAsynchronousSequencer::fvAsynchronousSequencer()
F_CE( throw( fException ) )
: _oThread ( )
, _bTerminateSequencerThread ( false )
, _bStop( false )
{
_oThread.create( this, _run );
}
// Only called by GUI thread
fvAsynchronousSequencer::~fvAsynchronousSequencer()
throw()
{
_bTerminateSequencerThread = true;
// wake up the thread, if necessary
_oRunCondition.notify_one();
// wait until the thread is terminated
{
boost::mutex::scoped_lock oLock( _oTerminateMutex );
_oTerminateCond.wait( oLock );
}
}
// Only called by GUI thread
void
fvAsynchronousSequencer::start()
{
_bStop = false;
_oRunCondition.notify_one();
}
// Only called by GUI thread
void
fvAsynchronousSequencer::stop()
throw()
{
_bStop = true;
// I would like to wait here until the _oThread is a in wait position.
}
void
fvAsynchronousSequencer::_run()
throw()
{
boost::mutex::scoped_lock oLock( _oRunMutex );
// Wait until someone calls start()
_oRunCondition.wait( oLock );
do
{
while( _bStop )
_oRunCondition.wait( oLock );
} while( !_bTerminateSequencerThread );
// now finish destructing the sequencer
_oTerminateCond.notify_one();
}
Thanks is advance,
Christian
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