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:
Alexey Rybalchenko
2014-08-26 15:35:50 +02:00
parent 7d7e1a1084
commit bd79420f93
18 changed files with 100 additions and 21 deletions

View File

@@ -124,8 +124,12 @@ int main(int argc, char** argv)
merger.ChangeState(FairMQMerger::SETINPUT);
merger.ChangeState(FairMQMerger::RUN);
char ch;
cin.get(ch);
// wait until the running thread has finished processing.
boost::unique_lock<boost::mutex> lock(merger.fRunningMutex);
while (!merger.fRunningFinished)
{
merger.fRunningCondition.wait(lock);
}
merger.ChangeState(FairMQMerger::STOP);
merger.ChangeState(FairMQMerger::END);