mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Condition check before ending the main thread.
Make sure the main thread waits for the child thread with the Run() method. * Add this at the end of your Run() method for each device: ``` boost::lock_guard<boost::mutex> lock(fRunningMutex); fRunningFinished = true; fRunningCondition.notify_one(); ``` * Then you must replace the `char ch; cin.get(ch);` in your main() function with: ``` boost::unique_lock<boost::mutex> lock(processor.fRunningMutex); while (!processor.fRunningFinished) { processor.fRunningCondition.wait(lock); } ```
This commit is contained in:
@@ -16,13 +16,16 @@
|
||||
#define FAIRMQSTATEMACHINE_H_
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <boost/msm/back/state_machine.hpp>
|
||||
#include <boost/msm/front/state_machine_def.hpp>
|
||||
#include <boost/msm/front/functor_row.hpp>
|
||||
#include <boost/msm/front/euml/common.hpp>
|
||||
#include <boost/msm/front/euml/operator.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
@@ -192,6 +195,11 @@ class FairMQStateMachine : public FairMQFSM::FairMQFSM
|
||||
FairMQStateMachine();
|
||||
virtual ~FairMQStateMachine();
|
||||
void ChangeState(int event);
|
||||
|
||||
// condition variable to notify parent thread about end of running state.
|
||||
boost::condition_variable fRunningCondition;
|
||||
boost::mutex fRunningMutex;
|
||||
bool fRunningFinished;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQSTATEMACHINE_H_ */
|
||||
|
Reference in New Issue
Block a user