]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/default_executor.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / example / default_executor.cpp
1 // Copyright (C) 2014 Vicente Botet
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/generic_executor_ref.hpp>
20 #include <string>
21 #include <iostream>
22
23 #include <boost/thread/caller_context.hpp>
24
25
26 boost::generic_executor_ref default_executor()
27 {
28 static boost::basic_thread_pool tp(4);
29 return boost::generic_executor_ref(tp);
30 }
31
32 void p2()
33 {
34 std::cout << BOOST_CONTEXTOF << std::endl;
35 boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
36 std::cout << BOOST_CONTEXTOF << std::endl;
37 }
38
39
40 void p1()
41 {
42 std::cout << BOOST_CONTEXTOF << std::endl;
43 boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
44 default_executor().submit(&p2);
45 boost::this_thread::sleep_for(boost::chrono::milliseconds(400));
46 std::cout << BOOST_CONTEXTOF << std::endl;
47 }
48
49 int main()
50 {
51 std::cout << BOOST_CONTEXTOF << std::endl;
52
53 default_executor().submit(&p1);
54
55 boost::this_thread::sleep_for(boost::chrono::seconds(5));
56
57 std::cout << BOOST_CONTEXTOF << std::endl;
58
59 return 1;
60
61 }