Skip to content
Snippets Groups Projects
Commit b76f3ada authored by vjpai's avatar vjpai
Browse files

Fix bug on shutdown case

parent b28456b1
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,7 @@ class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface { ...@@ -64,6 +64,7 @@ class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface {
}; };
grpc::mutex mu_; grpc::mutex mu_;
grpc::condition_variable cv_; grpc::condition_variable cv_;
grpc::condition_variable shutdown_cv_;
bool shutdown_; bool shutdown_;
std::queue<std::function<void()>> callbacks_; std::queue<std::function<void()>> callbacks_;
int reserve_threads_; int reserve_threads_;
......
...@@ -58,6 +58,9 @@ void DynamicThreadPool::DynamicThread::ThreadFunc() { ...@@ -58,6 +58,9 @@ void DynamicThreadPool::DynamicThread::ThreadFunc() {
pool_->dead_threads_.push_back(this); pool_->dead_threads_.push_back(this);
} }
} }
if ((pool_->shutdown_) && (pool_->nthreads_ == 0)) {
pool_->shutdown_cv_.notify_one();
}
} }
void DynamicThreadPool::ThreadFunc() { void DynamicThreadPool::ThreadFunc() {
...@@ -103,12 +106,12 @@ void DynamicThreadPool::ReapThreads(std::list<DynamicThread*>* tlist) { ...@@ -103,12 +106,12 @@ void DynamicThreadPool::ReapThreads(std::list<DynamicThread*>* tlist) {
} }
DynamicThreadPool::~DynamicThreadPool() { DynamicThreadPool::~DynamicThreadPool() {
{ grpc::unique_lock<grpc::mutex> lock(mu_);
grpc::lock_guard<grpc::mutex> lock(mu_); shutdown_ = true;
shutdown_ = true; cv_.notify_all();
cv_.notify_all(); while (nthreads_ != 0) {
shutdown_cv_.wait(lock);
} }
ReapThreads(&live_threads_);
ReapThreads(&dead_threads_); ReapThreads(&dead_threads_);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment