#ifndef _THREADPOOL_H_ #define _THREADPOOL_H_ #include #include #include #include #include #include #include class threadpool { private: std::size_t _concurrency; std::queue> _queue; std::mutex _mutex; std::condition_variable _cv; std::vector _workers; bool _enabled; public: threadpool(); threadpool(std::size_t concurrency); ~threadpool(); template std::future add_task(std::function func) { std::lock_guard lock(_mutex); std::packaged_task pt(func); std::future fut = pt.get_future(); _queue.push([&pt]{ pt(); }); _cv.notify_all(); return fut; } private: void worker_func(); }; #endif // _THREADPOOL_H_