Mercurial > hg > orthanc
diff Core/MultiThreading/BagOfRunnablesBySteps.cpp @ 1453:c0bdc47165ef
code to warn about possible threading problems
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 Jul 2015 12:26:44 +0200 |
parents | 6e7e5ed91c2d |
children | f967bdf8534e |
line wrap: on
line diff
--- a/Core/MultiThreading/BagOfRunnablesBySteps.cpp Thu Jul 02 11:35:41 2015 +0200 +++ b/Core/MultiThreading/BagOfRunnablesBySteps.cpp Thu Jul 02 12:26:44 2015 +0200 @@ -35,6 +35,7 @@ #include <stack> #include <boost/thread.hpp> +#include <glog/logging.h> namespace Orthanc { @@ -128,15 +129,10 @@ BagOfRunnablesBySteps::~BagOfRunnablesBySteps() { - StopAll(); - - // Stop the finish listener - pimpl_->stopFinishListener_ = true; - pimpl_->oneThreadIsStopped_.notify_one(); // Awakens the listener - - if (pimpl_->finishListener_->joinable()) + if (!pimpl_->stopFinishListener_) { - pimpl_->finishListener_->join(); + LOG(ERROR) << "INTERNAL ERROR: BagOfRunnablesBySteps::Finalize() should be invoked manually to avoid mess in the destruction order!"; + Finalize(); } } @@ -165,4 +161,24 @@ pimpl_->continue_ = true; } + + + + void BagOfRunnablesBySteps::Finalize() + { + if (!pimpl_->stopFinishListener_) + { + StopAll(); + + // Stop the finish listener + pimpl_->stopFinishListener_ = true; + pimpl_->oneThreadIsStopped_.notify_one(); // Awakens the listener + + if (pimpl_->finishListener_->joinable()) + { + pimpl_->finishListener_->join(); + } + } + } + }