diff --git a/src/zm_analysis_thread.cpp b/src/zm_analysis_thread.cpp index 143f970ac..4f1d1506b 100644 --- a/src/zm_analysis_thread.cpp +++ b/src/zm_analysis_thread.cpp @@ -9,7 +9,7 @@ AnalysisThread::AnalysisThread(std::shared_ptr monitor) : } AnalysisThread::~AnalysisThread() { - terminate_ = true; + Stop(); if (thread_.joinable()) thread_.join(); } diff --git a/src/zm_analysis_thread.h b/src/zm_analysis_thread.h index 9c7a770f7..8cf389e93 100644 --- a/src/zm_analysis_thread.h +++ b/src/zm_analysis_thread.h @@ -13,6 +13,8 @@ class AnalysisThread { AnalysisThread(AnalysisThread &rhs) = delete; AnalysisThread(AnalysisThread &&rhs) = delete; + void Stop() { terminate_ = true; } + private: void Run(); diff --git a/src/zmc.cpp b/src/zmc.cpp index 9d0051e78..c4ebe57c4 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -384,8 +384,8 @@ int main(int argc, char *argv[]) { } // end if zm_reload } // end while ! zm_terminate and connected - // Killoff the analysis threads. Don't need them spinning while we try to reconnect - analysis_threads.clear(); + for (std::unique_ptr &analysis_thread: analysis_threads) + analysis_thread->Stop(); for (size_t i = 0; i < monitors.size(); i++) { #if HAVE_RTSP_SERVER @@ -408,6 +408,9 @@ int main(int argc, char *argv[]) { camera->Close(); } + // Killoff the analysis threads. Don't need them spinning while we try to reconnect + analysis_threads.clear(); + #if HAVE_RTSP_SERVER if (rtsp_server_threads) { delete[] rtsp_server_threads;