1 // Copyright (C) 2014 Ian Forbed
2 // Copyright (C) 2014 Vicente J. Botet Escriba
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)
8 #include <boost/config.hpp>
9 #if ! defined BOOST_NO_CXX11_DECLTYPE
10 #define BOOST_RESULT_OF_USE_DECLTYPE
13 #define BOOST_THREAD_VERSION 4
14 #define BOOST_THREAD_PROVIDES_EXECUTORS
16 #include <boost/thread/executors/scheduler.hpp>
17 #include <boost/thread/executors/basic_thread_pool.hpp>
18 #include <boost/chrono/chrono_io.hpp>
21 #include <boost/core/lightweight_test.hpp>
23 using namespace boost::chrono
;
26 typedef boost::executors::basic_thread_pool thread_pool
;
30 //std::cout << "[" << __LINE__ << "] " << steady_clock::now() << std::endl;
31 std::cout
<< x
<< std::endl
;
34 void test_scheduler(const int n
, boost::scheduler
<>& sch
)
36 for(int i
= 1; i
<= n
; i
++)
38 sch
.submit_after(boost::bind(fn
,i
), seconds(i
));
39 sch
.submit_after(boost::bind(fn
,i
), milliseconds(i
*100));
43 void test_after(const int n
, boost::scheduler
<>& sch
)
45 for(int i
= 1; i
<= n
; i
++)
47 sch
.after(seconds(i
)).submit(boost::bind(fn
,i
));
48 sch
.after(milliseconds(i
*100)).submit(boost::bind(fn
,i
));
52 void test_at(const int n
, boost::scheduler
<>& sch
)
54 for(int i
= 1; i
<= n
; i
++)
56 sch
.at(steady_clock::now()+seconds(i
)).submit(boost::bind(fn
,i
));
57 sch
.at(steady_clock::now()+milliseconds(i
*100)).submit(boost::bind(fn
,i
));
61 void test_on(const int n
, boost::scheduler
<>& sch
, thread_pool
& tp
)
63 for(int i
= 1; i
<= n
; i
++)
65 sch
.on(tp
).after(seconds(i
)).submit(boost::bind(fn
,i
));
66 sch
.on(tp
).after(milliseconds(i
*100)).submit(boost::bind(fn
,i
));
73 boost::scheduler
<> sch
;
74 test_scheduler(5, sch
);
78 boost::this_thread::sleep_for(boost::chrono::seconds(10));
80 return boost::report_errors();