42#define DLL_EXPORT __declspec(dllexport)
64 threadpool(
size_t threads = std::thread::hardware_concurrency());
80 template <
class F,
class... Args>
81 std::future<std::result_of_t<F(Args...)>>
submit(F &&function, Args &&...args)
83 std::shared_ptr<std::packaged_task<std::result_of_t<F(Args...)>()>> packaged_task;
84 std::function<void()> work;
85 std::future<std::result_of_t<F(Args...)>> result;
87 packaged_task = std::make_shared<std::packaged_task<std::result_of_t<F(Args...)>()>>(std::bind(std::forward<F>(function), std::forward<Args>(args)...));
88 result = packaged_task->get_future();
90 work = [packaged_task]()
95 push_task(std::move(work));
113 void push_task(std::function<
void()> &&task);
114 bool pop_task(std::function<
void()> &task);
118 std::vector<std::thread> _workers;
119 std::queue<std::function<void()>> _tasks;
121 std::condition_variable _condition;
Definition threadpool.hpp:55
~threadpool()
destroys threadpool after calling shutdown if necessary
threadpool(size_t threads=std::thread::hardware_concurrency())
constructs a new threadpool
bool active() const
check if the threadpool is active
void shutdown()
shut down threadpool by joining threads and rejecting submissions
std::future< std::result_of_t< F(Args...)> > submit(F &&function, Args &&...args)
submits a function with its arguments to the threadpool
Definition threadpool.hpp:81
Definition threadpool.hpp:48
#define DLL_EXPORT
Definition threadpool.hpp:44