5 _workers.reserve(nbWorkers);
7 for (
size_t i = 0; i < _size; i++)
17 std::function<void()> action;
19 std::unique_lock<std::mutex> lock(_mtx);
20 _cv.wait(lock, [&] {
return _stop || !_jobs.empty(); });
22 if (_stop || _jobs.empty())
25 action = _jobs.front();
35 std::lock_guard<std::mutex> lock(_mtx);
41 for (
size_t i = 0; i < _size; i++)
43 if (_workers[i].joinable())
49 std::lock_guard<std::mutex> lock(_mtx);
50 while (!_jobs.empty())
57 std::lock_guard<std::mutex> lock(_mtx);
58 _jobs.push(jobToExecute);
66 std::lock_guard<std::mutex> lock(_mtx);
67 _jobs.push([&jobToExecute]() { jobToExecute.
start(); });
Interface for defining jobs to be executed by the worker pool. Classes implementing this interface mu...
void addJob(const std::function< void()> &jobToExecute)
WorkerPool(const int &nbWorkers)