default_executor.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2014 Vicente Botet
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/config.hpp>
  6. #if ! defined BOOST_NO_CXX11_DECLTYPE
  7. #define BOOST_RESULT_OF_USE_DECLTYPE
  8. #endif
  9. #define BOOST_THREAD_VERSION 4
  10. #define BOOST_THREAD_PROVIDES_EXECUTORS
  11. //#define BOOST_THREAD_USES_LOG
  12. #define BOOST_THREAD_USES_LOG_THREAD_ID
  13. #define BOOST_THREAD_QUEUE_DEPRECATE_OLD
  14. #include <boost/thread/caller_context.hpp>
  15. #include <boost/thread/executors/basic_thread_pool.hpp>
  16. #include <boost/thread/executors/generic_executor_ref.hpp>
  17. #include <string>
  18. #include <iostream>
  19. #include <boost/thread/caller_context.hpp>
  20. boost::generic_executor_ref default_executor()
  21. {
  22. static boost::basic_thread_pool tp(4);
  23. return boost::generic_executor_ref(tp);
  24. }
  25. void p2()
  26. {
  27. std::cout << BOOST_CONTEXTOF << std::endl;
  28. boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
  29. std::cout << BOOST_CONTEXTOF << std::endl;
  30. }
  31. void p1()
  32. {
  33. std::cout << BOOST_CONTEXTOF << std::endl;
  34. boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
  35. default_executor().submit(&p2);
  36. boost::this_thread::sleep_for(boost::chrono::milliseconds(400));
  37. std::cout << BOOST_CONTEXTOF << std::endl;
  38. }
  39. int main()
  40. {
  41. std::cout << BOOST_CONTEXTOF << std::endl;
  42. default_executor().submit(&p1);
  43. boost::this_thread::sleep_for(boost::chrono::seconds(5));
  44. std::cout << BOOST_CONTEXTOF << std::endl;
  45. return 1;
  46. }