From 9b695ca3e229a563b9ed95b10ffdd3a454ea2bc6 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 26 Dec 2023 16:04:17 +0900 Subject: [PATCH] Fix deadlock issue This patch fixes deadlock issue. When CynaraThread was blocked from WaitAndPop() and the instance was desctucted at the same time, CynaraThread occurs deadlock. Change-Id: Iee2c6fb02dd1f5fd6b9b5331c4d87ddbbb880697 Signed-off-by: Changgyu Choi --- src/cynara_thread.cc | 6 ++---- src/cynara_thread.hh | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/cynara_thread.cc b/src/cynara_thread.cc index 17b7ee3..a5a2f67 100644 --- a/src/cynara_thread.cc +++ b/src/cynara_thread.cc @@ -41,7 +41,7 @@ CynaraThread::CynaraThread() { // LCOV_EXCL_START CynaraThread::~CynaraThread() { - finished_ = true; + queue_.Push(Job()); thread_.join(); } // LCOV_EXCL_STOP @@ -49,10 +49,8 @@ CynaraThread::~CynaraThread() { void CynaraThread::ThreadRun() { while (true) { Job job = queue_.WaitAndPop(); - if (finished_) + if (job.Do() == Job::Type::Finish) return; // LCOV_EXCL_LINE - - job.Do(); } } diff --git a/src/cynara_thread.hh b/src/cynara_thread.hh index 04d76cd..3babdd3 100644 --- a/src/cynara_thread.hh +++ b/src/cynara_thread.hh @@ -17,7 +17,6 @@ #ifndef CYNARA_THREAD_HH_ #define CYNARA_THREAD_HH_ -#include #include #include #include @@ -59,7 +58,6 @@ class CynaraThread { Job Pop(); std::thread thread_; - std::atomic finished_ = false; mutable tizen_base::SharedQueue queue_; }; -- 2.7.4