scheduled_thread_pool.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2014 Ian Forbed
  2. // Copyright (C) 2014 Vicente J. Botet Escriba
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_THREAD_EXECUTORS_SCHEDULED_THREAD_POOL_HPP
  8. #define BOOST_THREAD_EXECUTORS_SCHEDULED_THREAD_POOL_HPP
  9. #include <boost/thread/detail/config.hpp>
  10. #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined BOOST_THREAD_PROVIDES_EXECUTORS && defined BOOST_THREAD_USES_MOVE
  11. #include <boost/thread/executors/detail/scheduled_executor_base.hpp>
  12. namespace boost
  13. {
  14. namespace executors
  15. {
  16. class scheduled_thread_pool : public detail::scheduled_executor_base<>
  17. {
  18. private:
  19. thread_group _workers;
  20. public:
  21. scheduled_thread_pool(size_t num_threads) : super()
  22. {
  23. for(size_t i = 0; i < num_threads; i++)
  24. {
  25. _workers.create_thread(bind(&super::loop, this));
  26. }
  27. }
  28. ~scheduled_thread_pool()
  29. {
  30. this->close();
  31. _workers.interrupt_all();
  32. _workers.join_all();
  33. }
  34. private:
  35. typedef detail::scheduled_executor_base<> super;
  36. }; //end class
  37. } //end executors namespace
  38. using executors::scheduled_thread_pool;
  39. } //end boost
  40. #endif
  41. #endif