Fix deadlock issue 53/303353/4
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 26 Dec 2023 07:04:17 +0000 (16:04 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 26 Dec 2023 07:25:38 +0000 (07:25 +0000)
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 <changyu.choi@samsung.com>
src/cynara_thread.cc
src/cynara_thread.hh

index 17b7ee3..a5a2f67 100644 (file)
@@ -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();
   }
 }
 
index 04d76cd..3babdd3 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef CYNARA_THREAD_HH_
 #define CYNARA_THREAD_HH_
 
-#include <atomic>
 #include <functional>
 #include <shared-queue.hpp>
 #include <thread>
@@ -59,7 +58,6 @@ class CynaraThread {
   Job Pop();
 
   std::thread thread_;
-  std::atomic<bool> finished_ = false;
   mutable tizen_base::SharedQueue<Job> queue_;
 };