2 // impl/thread_pool.ipp
3 // ~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_IMPL_THREAD_POOL_IPP
12 #define BOOST_ASIO_IMPL_THREAD_POOL_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/thread_pool.hpp>
21 #include <boost/asio/detail/push_options.hpp>
26 struct thread_pool::thread_function
28 detail::scheduler* scheduler_;
32 boost::system::error_code ec;
37 thread_pool::thread_pool()
38 : scheduler_(use_service<detail::scheduler>(*this))
40 scheduler_.work_started();
42 thread_function f = { &scheduler_ };
43 std::size_t num_threads = detail::thread::hardware_concurrency() * 2;
44 threads_.create_threads(f, num_threads ? num_threads : 2);
47 thread_pool::thread_pool(std::size_t num_threads)
48 : scheduler_(use_service<detail::scheduler>(*this))
50 scheduler_.work_started();
52 thread_function f = { &scheduler_ };
53 threads_.create_threads(f, num_threads);
56 thread_pool::~thread_pool()
62 void thread_pool::stop()
67 void thread_pool::join()
69 scheduler_.work_finished();
76 #include <boost/asio/detail/pop_options.hpp>
78 #endif // BOOST_ASIO_IMPL_THREAD_POOL_IPP