diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp index 38c0589a73cd32cc6436a6d0cd0097075af1af82..a50feadef500666dab341a9718fb98b71f0593f8 100644 --- a/MantidPlot/src/ProjectRecovery.cpp +++ b/MantidPlot/src/ProjectRecovery.cpp @@ -291,7 +291,7 @@ void ProjectRecovery::stopProjectSaving() { } if (m_backgroundSavingThread.joinable()) { - m_backgroundSavingThread.join(); + m_backgroundSavingThread.detach(); } } @@ -318,7 +318,10 @@ bool ProjectRecovery::openInEditor(const Poco::Path &inputFolder) { /// them void ProjectRecovery::projectSavingThreadWrapper() { try { - projectSavingThread(); + projectSavingThread(); + } + catch (Mantid::API::Algorithm::CancelException) { + return; } catch (std::exception const &e) { std::string preamble("Project recovery has stopped. Please report" " this to the development team.\nException:\n"); @@ -337,15 +340,17 @@ void ProjectRecovery::projectSavingThreadWrapper() { */ void ProjectRecovery::projectSavingThread() { while (!m_stopBackgroundThread) { - std::unique_lock<std::mutex> lock(m_notifierMutex); - // The condition variable releases the lock until the var changes - if (m_threadNotifier.wait_for(lock, TIME_BETWEEN_SAVING, [this]() { - return m_stopBackgroundThread.load(); - })) { - // Exit thread - g_log.debug("Project Recovery: Stopping background saving thread"); - return; - } + { // Ensure the lock only exists as long as the conditional variable + std::unique_lock<std::mutex> lock(m_notifierMutex); + // The condition variable releases the lock until the var changes + if (m_threadNotifier.wait_for(lock, TIME_BETWEEN_SAVING, [this]() { + return m_stopBackgroundThread.load(); + })) { + // Exit thread + g_log.debug("Project Recovery: Stopping background saving thread"); + return; + } + } // "Timeout" - Save out again const auto &ads = Mantid::API::AnalysisDataService::Instance(); @@ -433,7 +438,7 @@ void ProjectRecovery::saveWsHistories(const Poco::Path &historyDestFolder) { alg->setPropertyValue("Filename", destFilename.toString()); alg->setPropertyValue("StartTimestamp", startTime); - alg->execute(); + alg->execute(); } }