13 #include <condition_variable> 21 std::size_t
Size()
const;
22 void Resize(
size_t num_threads);
24 template<
typename FuncType,
typename...ArgTypes>
25 auto Push(FuncType &&func, ArgTypes&&...
args) -> std::future<decltype(func(
args...))>;
34 bool ReadyToAct(
size_t ithread, std::unique_ptr<std::function<
void()> > &task);
38 using FuncPtr = std::unique_ptr<std::function<void()> >;
57 std::vector<std::unique_ptr<std::thread> >
threads_;
62 std::condition_variable
cv_;
65 template<
typename FuncType,
typename...ArgTypes>
67 auto task = std::make_shared<std::packaged_task<decltype(func(
args...))()> >(std::bind(std::forward<FuncType>(func), std::forward<ArgTypes>(
args)...));
68 std::unique_ptr<std::function<void()> > pkg_func(
new std::function<
void()>([task](){(*task)();}));
70 std::lock_guard<std::mutex> lock(
mutex_);
72 return task->get_future();
std::atomic< bool > stop_at_empty_
ThreadPool & operator=(const ThreadPool &)=delete
void DoTasksFromQueue(size_t ithread)
std::queue< FuncPtr > queue_
std::vector< std::shared_ptr< std::atomic< bool > > > stop_thread_now_
auto Push(FuncType &&func, ArgTypes &&...args) -> std::future< decltype(func(args...))>
Queue & operator=(const Queue &)=delete
bool ReadyToAct(size_t ithread, std::unique_ptr< std::function< void()> > &task)
std::vector< std::unique_ptr< std::thread > > threads_
void Resize(size_t num_threads)
std::unique_ptr< std::function< void()> > FuncPtr
std::condition_variable cv_