scheduled_thread_pool.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/executors/detail/scheduled_executor_base.hpp>
  10. namespace boost
  11. {
  12. namespace executors
  13. {
  14. class scheduled_thread_pool : public detail::scheduled_executor_base<>
  15. {
  16. private:
  17. thread_group _workers;
  18. public:
  19. scheduled_thread_pool(size_t num_threads) : super()
  20. {
  21. for(size_t i = 0; i < num_threads; i++)
  22. {
  23. _workers.create_thread(bind(&super::loop, this));
  24. }
  25. }
  26. ~scheduled_thread_pool()
  27. {
  28. this->close();
  29. _workers.interrupt_all();
  30. _workers.join_all();
  31. }
  32. private:
  33. typedef detail::scheduled_executor_base<> super;
  34. }; //end class
  35. } //end executors namespace
  36. using executors::scheduled_thread_pool;
  37. } //end boost
  38. #endif