in dispenso/thread_pool.cpp [45:70]
void ThreadPool::resize(ssize_t sn) {
assert(sn > 0);
size_t n = static_cast<size_t>(sn);
std::lock_guard<std::mutex> lk(threadsMutex_);
if (n < threads_.size()) {
for (size_t i = n; i < threads_.size(); ++i) {
threads_[i].running.store(false, std::memory_order_release);
}
for (size_t i = n; i < threads_.size(); ++i) {
threads_[i].thread.join();
}
while (threads_.size() > n) {
threads_.pop_back();
}
} else if (n > threads_.size()) {
for (size_t i = threads_.size(); i < n; ++i) {
threads_.emplace_back();
auto& back = threads_.back();
back.running = true;
back.thread = std::thread([this, &running = back.running]() { threadLoop(running); });
}
}
poolLoadFactor_.store(static_cast<ssize_t>(n * poolLoadMultiplier_), std::memory_order_relaxed);
numThreads_.store(sn, std::memory_order_relaxed);
}