27 std::cerr <<
"[threadPool] Warning: clear() called (probably from a " 29 <<
tasks_.size() <<
" pending tasks. Aborting them.\n";
32 if (t.joinable()) t.join();
43 for (std::size_t i = 0; i < num_threads; ++i)
49 std::function<void()> task;
51 std::unique_lock<std::mutex> lock(queue_mutex_);
52 condition_.wait(lock, [this] {
53 return do_stop_ || !tasks_.empty();
56 task = std::move(tasks_.front());
62 catch (std::exception& e)
64 std::cerr <<
"[thread-pool] Exception:\n" 65 << mrpt::exception_to_str(e) <<
"\n";
std::atomic_bool do_stop_
std::condition_variable condition_
std::vector< std::thread > threads_
std::queue< std::function< void()> > tasks_
void resize(std::size_t num_threads)
void clear()
Stops all working jobs.
std::size_t pendingTasks() const noexcept
Returns the number of enqueued tasks, currently waiting for a free working thread to process them...