1 // Copyright (C) 2015 Vicente J. Botet Escriba 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 6 #include <boost/config.hpp> 7 #if ! defined BOOST_NO_CXX11_DECLTYPE 8 #define BOOST_RESULT_OF_USE_DECLTYPE 9 #endif 10 11 #define BOOST_THREAD_VERSION 4 12 #define BOOST_THREAD_PROVIDES_EXECUTORS 13 //#define BOOST_THREAD_USES_LOG 14 #define BOOST_THREAD_USES_LOG_THREAD_ID 15 #define BOOST_THREAD_QUEUE_DEPRECATE_OLD 16 17 #include <boost/thread/caller_context.hpp> 18 #include <boost/thread/executors/basic_thread_pool.hpp> 19 #include <boost/thread/executors/serial_executor_cont.hpp> 20 #include <boost/thread/executors/executor.hpp> 21 #include <boost/thread/executors/executor_adaptor.hpp> 22 #include <boost/thread/executor.hpp> 23 #include <boost/thread/future.hpp> 24 #include <boost/assert.hpp> 25 #include <string> 26 #include <iostream> 27 p1()28void p1() 29 { 30 std::cout << BOOST_CONTEXTOF << std::endl; 31 boost::this_thread::sleep_for(boost::chrono::milliseconds(30)); 32 std::cout << BOOST_CONTEXTOF << std::endl; 33 } 34 p2()35void p2() 36 { 37 std::cout << BOOST_CONTEXTOF << std::endl; 38 boost::this_thread::sleep_for(boost::chrono::milliseconds(10)); 39 std::cout << BOOST_CONTEXTOF << std::endl; 40 } 41 f1()42int f1() 43 { 44 // std::cout << BOOST_CONTEXTOF << std::endl; 45 boost::this_thread::sleep_for(boost::chrono::seconds(1)); 46 return 1; 47 } f2(int i)48int f2(int i) 49 { 50 // std::cout << BOOST_CONTEXTOF << std::endl; 51 boost::this_thread::sleep_for(boost::chrono::seconds(2)); 52 return i + 1; 53 } 54 submit_some(boost::serial_executor_cont & tp)55void submit_some(boost::serial_executor_cont& tp) 56 { 57 std::cout << BOOST_CONTEXTOF << std::endl; 58 for (int i = 0; i < 3; ++i) { 59 std::cout << BOOST_CONTEXTOF << std::endl; 60 tp.submit(&p2); 61 } 62 for (int i = 0; i < 3; ++i) { 63 std::cout << BOOST_CONTEXTOF << std::endl; 64 tp.submit(&p1); 65 } 66 std::cout << BOOST_CONTEXTOF << std::endl; 67 68 } 69 70 at_th_entry(boost::basic_thread_pool &)71void at_th_entry(boost::basic_thread_pool& ) 72 { 73 74 } 75 test_executor_adaptor()76int test_executor_adaptor() 77 { 78 // std::cout << BOOST_CONTEXTOF << std::endl; 79 { 80 try 81 { 82 83 #if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 84 // std::cout << BOOST_CONTEXTOF << std::endl; 85 { 86 boost::basic_thread_pool ea1(4); 87 boost::serial_executor_cont ea2(ea1); 88 submit_some(ea2); 89 boost::this_thread::sleep_for(boost::chrono::seconds(10)); 90 } 91 #endif 92 // std::cout << BOOST_CONTEXTOF << std::endl; 93 } 94 catch (std::exception& ex) 95 { 96 std::cout << "ERROR= " << ex.what() << "" << std::endl; 97 return 1; 98 } 99 catch (...) 100 { 101 std::cout << " ERROR= exception thrown" << std::endl; 102 return 2; 103 } 104 } 105 // std::cout << BOOST_CONTEXTOF << std::endl; 106 return 0; 107 } 108 109 main()110int main() 111 { 112 return test_executor_adaptor(); 113 } 114