19 typedef TaskPool::__task __task;
22 std::vector<std::thread> _thread;
24 std::condition_variable _cv;
37 for (
auto &t : _thread) {
38 t = std::thread(&ThreadPool::_main,
this);
51 template<
class Function,
class... Args>
52 auto push(Function &&newTask, Args &&...
args) {
53 std::lock_guard lg(_lock);
54 auto future = TaskPool::push(std::forward<Function>(newTask), std::forward<Args>(
args)...);
60 void pushDelayed(std::pair<__time_point, __task> &&task) {
61 std::lock_guard lg(_lock);
63 TaskPool::pushDelayed(std::move(task));
66 template<
class Function,
class X,
class Y,
class... Args>
67 auto pushDelayed(Function &&newTask, std::chrono::duration<X, Y> duration, Args &&...
args) {
68 std::lock_guard lg(_lock);
69 auto future = TaskPool::pushDelayed(std::forward<Function>(newTask), duration, std::forward<Args>(
args)...);
76 void start(
int threads) {
79 _thread.resize(threads);
81 for (
auto &t : _thread) {
82 t = std::thread(&ThreadPool::_main,
this);
87 std::lock_guard lg(_lock);
94 for (
auto &t : _thread) {
102 if (
auto task = this->pop()) {
105 std::unique_lock uniq_lock(_lock);
115 if (
auto tp = next()) {
116 _cv.wait_until(uniq_lock, *tp);
124 while (
auto task = this->pop()) {