Summary:
This draining mechanism should not be run during `JoinThreads()` because it can detach threads that will be joined. Joining detached threads would throw an exception.
With this PR, we skip draining when `JoinThreads()` has already decided what threads to `join()`, so the threads will exit naturally once the work queue empties.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8635
Test Plan: verified it unblocked using `WaitForJobsAndJoinAllThreads()` in https://github.com/facebook/rocksdb/issues/8611.
Reviewed By: riversand963
Differential Revision:
D30174587
Pulled By: ajkr
fbshipit-source-id:
144966398a607987e0763c7152a0f653fdbf3c8b
queue_.empty()) {
break;
}
- }
-
- if (IsLastExcessiveThread(thread_id)) {
+ } else if (IsLastExcessiveThread(thread_id)) {
// Current thread is the last generated one and is excessive.
// We always terminate excessive thread in the reverse order of
- // generation time.
+ // generation time. But not when `exit_all_threads_ == true`,
+ // otherwise `JoinThreads()` could try to `join()` a `detach()`ed
+ // thread.
auto& terminating_thread = bgthreads_.back();
terminating_thread.detach();
bgthreads_.pop_back();