8 #ifndef PAAL_THREAD_POOL_HPP
9 #define PAAL_THREAD_POOL_HPP
11 #define BOOST_ERROR_CODE_HEADER_ONLY
12 #define BOOST_SYSTEM_NO_DEPRECATED
14 #include <boost/asio/io_service.hpp>
26 boost::asio::io_service m_io_service;
27 std::vector<std::thread> m_threadpool;
28 std::size_t m_threads_besides_current;
32 thread_pool(std::size_t size) : m_threads_besides_current(size - 1) {
34 m_threadpool.reserve(m_threads_besides_current);
38 template <
typename Functor>
41 m_io_service.post(std::move(f));
46 auto io_run = [&](){m_io_service.run();};
47 for(std::size_t i = 0; i < m_threads_besides_current; ++i) {
48 m_threadpool.emplace_back(io_run);
53 for (
auto & thread : m_threadpool) thread.join();
void post(Functor f)
post new task
simple threadpool, class uses also current thread!
void run()
run all posted tasks (blocking)
thread_pool(std::size_t size)
constructor