mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-12-15 15:30:16 +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:
@@ -124,8 +124,12 @@ int main(int argc, char** argv)
|
||||
splitter.ChangeState(FairMQSplitter::SETINPUT);
|
||||
splitter.ChangeState(FairMQSplitter::RUN);
|
||||
|
||||
char ch;
|
||||
cin.get(ch);
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(splitter.fRunningMutex);
|
||||
while (!splitter.fRunningFinished)
|
||||
{
|
||||
splitter.fRunningCondition.wait(lock);
|
||||
}
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::STOP);
|
||||
splitter.ChangeState(FairMQSplitter::END);
|
||||
|
||||
Reference in New Issue
Block a user