• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2014 Ian Forbed
2 // Copyright (C) 2014 Vicente J. Botet Escriba
3 //
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)
6 //
7 
8 #include <boost/config.hpp>
9 #if ! defined  BOOST_NO_CXX11_DECLTYPE
10 #define BOOST_RESULT_OF_USE_DECLTYPE
11 #endif
12 
13 #define BOOST_THREAD_VERSION 4
14 #define BOOST_THREAD_PROVIDES_EXECUTORS
15 
16 #include <boost/function.hpp>
17 #include <boost/thread/executors/executor.hpp>
18 #include <boost/thread/executors/basic_thread_pool.hpp>
19 #include <boost/thread/executors/scheduling_adaptor.hpp>
20 #include <boost/chrono/chrono_io.hpp>
21 
22 #include <boost/core/lightweight_test.hpp>
23 
24 using namespace boost::chrono;
25 
26 
27 typedef boost::executors::basic_thread_pool thread_pool;
28 
fn(int x)29 void fn(int x)
30 {
31   //std::cout << "[" << __LINE__ << "] " << steady_clock::now() << std::endl;
32     std::cout << x << std::endl;
33 }
34 
test_timing(const int n)35 void test_timing(const int n)
36 {
37     thread_pool tp(4);
38     boost::scheduling_adaptor<thread_pool> sa(tp);
39     for(int i = 1; i <= n; i++)
40     {
41         sa.submit_after(boost::bind(fn,i),seconds(i));
42         sa.submit_after(boost::bind(fn,i), milliseconds(i*100));
43     }
44     boost::this_thread::sleep_for(boost::chrono::seconds(10));
45 }
46 
main()47 int main()
48 {
49   steady_clock::time_point start = steady_clock::now();
50   test_timing(5);
51   steady_clock::duration diff = steady_clock::now() - start;
52   BOOST_TEST(diff > seconds(5));
53   return boost::report_errors();
54 }
55