1 // Copyright (C) 2012-2013 Vicente Botet
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)
6 #include <boost/config.hpp>
7 #if ! defined BOOST_NO_CXX11_DECLTYPE
8 #define BOOST_RESULT_OF_USE_DECLTYPE
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
17 #include <boost/thread/caller_context.hpp>
18 #include <boost/thread/executors/basic_thread_pool.hpp>
19 #include <boost/thread/executors/loop_executor.hpp>
20 #include <boost/thread/executors/serial_executor.hpp>
21 #include <boost/thread/executors/inline_executor.hpp>
22 #include <boost/thread/executors/thread_executor.hpp>
23 #include <boost/thread/executors/executor.hpp>
24 #include <boost/thread/executors/executor_adaptor.hpp>
25 #include <boost/thread/executor.hpp>
26 #include <boost/thread/future.hpp>
27 #include <boost/assert.hpp>
33 // std::cout << BOOST_CONTEXTOF << std::endl;
34 //boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
39 // std::cout << BOOST_CONTEXTOF << std::endl;
40 //boost::this_thread::sleep_for(boost::chrono::seconds(10));
45 // std::cout << BOOST_CONTEXTOF << std::endl;
46 boost::this_thread::sleep_for(boost::chrono::seconds(1));
51 // std::cout << BOOST_CONTEXTOF << std::endl;
52 boost::this_thread::sleep_for(boost::chrono::seconds(2));
56 void submit_some(boost::executor& tp)
58 for (int i = 0; i < 3; ++i) {
61 for (int i = 0; i < 3; ++i) {
68 void at_th_entry(boost::basic_thread_pool& )
73 int test_executor_adaptor()
75 // std::cout << BOOST_CONTEXTOF << std::endl;
80 boost::executor_adaptor < boost::basic_thread_pool > ea(4);
83 boost::future<int> t1 = boost::async(ea, &f1);
84 boost::future<int> t2 = boost::async(ea, &f1);
85 // std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
86 // std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
90 boost::basic_thread_pool ea3(1);
91 boost::future<int> t1 = boost::async(ea3, &f1);
92 boost::future<int> t2 = boost::async(ea3, &f1);
93 //boost::future<int> t2 = boost::async(ea3, f2, 1); // todo this doesn't compiles yet on C++11
94 //boost::future<int> t2 = boost::async(ea3, boost::bind(f2, 1)); // todo this doesn't compiles yet on C++98
95 // std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
96 // std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
100 // std::cout << BOOST_CONTEXTOF << std::endl;
102 boost::executor_adaptor < boost::loop_executor > ea2;
104 ea2.underlying_executor().run_queued_closures();
106 #if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
107 // std::cout << BOOST_CONTEXTOF << std::endl;
109 boost::executor_adaptor < boost::basic_thread_pool > ea1(4);
110 boost::executor_adaptor < boost::serial_executor > ea2(ea1);
114 // std::cout << BOOST_CONTEXTOF << std::endl;
116 boost::executor_adaptor < boost::inline_executor > ea1;
119 // std::cout << BOOST_CONTEXTOF << std::endl;
121 boost::executor_adaptor < boost::thread_executor > ea1;
124 // std::cout << BOOST_CONTEXTOF << std::endl;
126 boost::basic_thread_pool ea(4, at_th_entry);
127 boost::future<int> t1 = boost::async(ea, &f1);
128 // std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
131 catch (std::exception& ex)
133 std::cout << "ERROR= " << ex.what() << "" << std::endl;
138 std::cout << " ERROR= exception thrown" << std::endl;
142 // std::cout << BOOST_CONTEXTOF << std::endl;
149 return test_executor_adaptor();