From 5b2cb64bfb87e1d77025220d23ac7bf3ac8ecefd Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 3 Oct 2017 16:25:42 -0700 Subject: [PATCH] Prevent threads from respawning during joining Summary: Previously the thread pool might be non-empty after joining since concurrent submissions could spawn new threads. This problem didn't affect our background flush/compaction thread pools because the `shutting_down_` flag prevented new jobs from being submitted during/after joining. But I wanted to be able to reuse the `ThreadPool` without such external synchronization. Closes https://github.com/facebook/rocksdb/pull/2953 Differential Revision: D5951920 Pulled By: ajkr fbshipit-source-id: 0efec7d0056d36d1338367da75e8b0c089bbc973 --- util/threadpool_imp.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/threadpool_imp.cc b/util/threadpool_imp.cc index f38e6422b..10b5d4361 100644 --- a/util/threadpool_imp.cc +++ b/util/threadpool_imp.cc @@ -147,6 +147,9 @@ void ThreadPoolImpl::Impl::JoinThreads(bool wait_for_jobs_to_complete) { wait_for_jobs_to_complete_ = wait_for_jobs_to_complete; exit_all_threads_ = true; + // prevent threads from being recreated right after they're joined, in case + // the user is concurrently submitting jobs. + total_threads_limit_ = 0; lock.unlock();