Merge pull request #3157 from Carbenium/zmc-deadlock

Fix a possible deadlock on zmc shutdown and reconnect
pull/3159/head
Isaac Connor 2021-02-11 11:28:36 -05:00 committed by GitHub
commit 2742485a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -9,7 +9,7 @@ AnalysisThread::AnalysisThread(std::shared_ptr<Monitor> monitor) :
}
AnalysisThread::~AnalysisThread() {
terminate_ = true;
Stop();
if (thread_.joinable())
thread_.join();
}

View File

@ -13,6 +13,8 @@ class AnalysisThread {
AnalysisThread(AnalysisThread &rhs) = delete;
AnalysisThread(AnalysisThread &&rhs) = delete;
void Stop() { terminate_ = true; }
private:
void Run();

View File

@ -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<AnalysisThread> &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;