thread pool: add function to detach threads

This commit is contained in:
François-Simon Fauteux-Chapleau authored and Adrien Béraud committed 2024-04-23 14:02:32 -04:00
1 parent 386943de39
commit f2cee8e9ce
2 files changed
+12 -1

No files matched your search

+11 -1
View File
@@ -85,7 +85,7 @@ ThreadPool::run(std::function<void()>&& cb)
auto waitCond = [&](){ return not running_ or not tasks_.empty(); };
if (permanent_thread)
cv_.wait(l, waitCond);
else
else
cv_.wait_for(l, e, waitCond);
readyThreads_--;
if (not running_ or tasks_.empty())
@@ -166,6 +166,16 @@ ThreadPool::join()
tasks_ = {};
}
void
ThreadPool::detach()
{
stop(false);
for (auto& t : threads_)
t->detach();
threads_.clear();
tasks_ = {};
}
void
Executor::run(std::function<void()>&& task)
{