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.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()28 void 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()35 void 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()42 int 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)48 int 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 & tp)55 void submit_some(boost::serial_executor& tp)
56 {
57   for (int i = 0; i < 3; ++i) {
58     std::cout << BOOST_CONTEXTOF << std::endl;
59     tp.submit(&p2);
60   }
61   for (int i = 0; i < 3; ++i) {
62     std::cout << BOOST_CONTEXTOF << std::endl;
63     tp.submit(&p1);
64   }
65 
66 }
67 
68 
at_th_entry(boost::basic_thread_pool &)69 void at_th_entry(boost::basic_thread_pool& )
70 {
71 
72 }
73 
test_executor_adaptor()74 int test_executor_adaptor()
75 {
76   {
77     try
78     {
79 
80 #if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
81       {
82         boost::basic_thread_pool ea1(4);
83         boost::serial_executor ea2(ea1);
84         submit_some(ea2);
85         boost::this_thread::sleep_for(boost::chrono::seconds(10));
86       }
87 #endif
88     }
89     catch (std::exception& ex)
90     {
91       std::cout << "ERROR= " << ex.what() << "" << std::endl;
92       return 1;
93     }
94     catch (...)
95     {
96       std::cout << " ERROR= exception thrown" << std::endl;
97       return 2;
98     }
99   }
100   return 0;
101 }
102 
103 
main()104 int main()
105 {
106   return test_executor_adaptor();
107 }
108