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>
// LCOV_EXCL_START
CynaraThread::~CynaraThread() {
- finished_ = true;
+ queue_.Push(Job());
thread_.join();
}
// LCOV_EXCL_STOP
void CynaraThread::ThreadRun() {
while (true) {
Job job = queue_.WaitAndPop();
- if (finished_)
+ if (job.Do() == Job::Type::Finish)
return; // LCOV_EXCL_LINE
-
- job.Do();
}
}
#ifndef CYNARA_THREAD_HH_
#define CYNARA_THREAD_HH_
-#include <atomic>
#include <functional>
#include <shared-queue.hpp>
#include <thread>
Job Pop();
std::thread thread_;
- std::atomic<bool> finished_ = false;
mutable tizen_base::SharedQueue<Job> queue_;
};