16 typedef TaskPool::__task __task;
19 std::vector<std::thread> _thread;
21 std::condition_variable _cv;
28 _continue {
false } {}
31 _thread(threads), _continue {
true } {
32 for (
auto &t : _thread) {
33 t = std::thread(&ThreadPool::_main,
this);
38 if (!_continue)
return;
44 template <
class Function,
class... Args>
46 push(Function &&newTask, Args &&...
args) {
47 std::lock_guard lg(_lock);
48 auto future = TaskPool::push(std::forward<Function>(newTask), std::forward<Args>(
args)...);
55 pushDelayed(std::pair<__time_point, __task> &&task) {
56 std::lock_guard lg(_lock);
58 TaskPool::pushDelayed(std::move(task));
61 template <
class Function,
class X,
class Y,
class... Args>
63 pushDelayed(Function &&newTask, std::chrono::duration<X, Y> duration, Args &&...
args) {
64 std::lock_guard lg(_lock);
65 auto future = TaskPool::pushDelayed(std::forward<Function>(newTask), duration, std::forward<Args>(
args)...);
76 _thread.resize(threads);
78 for (
auto &t : _thread) {
79 t = std::thread(&ThreadPool::_main,
this);
85 std::lock_guard lg(_lock);
93 for (
auto &t : _thread) {
102 if (
auto task = this->pop()) {
106 std::unique_lock uniq_lock(_lock);
116 if (
auto tp = next()) {
117 _cv.wait_until(uniq_lock, *tp);
126 while (
auto task = this->pop()) {