]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/thread_pool.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / thread / example / thread_pool.cpp
1 // Copyright (C) 2012-2013 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
8 #define BOOST_THREAD_VERSION 5
9 //#define BOOST_THREAD_USES_LOG
10 #define BOOST_THREAD_USES_LOG_THREAD_ID
11 #define BOOST_THREAD_QUEUE_DEPRECATE_OLD
12 #if ! defined BOOST_NO_CXX11_DECLTYPE
13 #define BOOST_RESULT_OF_USE_DECLTYPE
14 #endif
15
16 #include <boost/thread/detail/log.hpp>
17 #include <boost/thread/executors/basic_thread_pool.hpp>
18 #include <boost/thread/thread_only.hpp>
19 #include <boost/assert.hpp>
20 #include <string>
21
22 #ifdef BOOST_MSVC
23 #pragma warning(disable: 4127) // conditional expression is constant
24 #endif
25
26 void p1()
27 {
28 BOOST_THREAD_LOG
29 << boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG;
30 }
31
32 void p2()
33 {
34 BOOST_THREAD_LOG
35 << boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG;
36 }
37
38 void submit_some(boost::basic_thread_pool& tp) {
39 tp.submit(&p1);
40 tp.submit(&p2);
41 tp.submit(&p1);
42 tp.submit(&p2);
43 tp.submit(&p1);
44 tp.submit(&p2);
45 tp.submit(&p1);
46 tp.submit(&p2);
47 tp.submit(&p1);
48 tp.submit(&p2);
49 }
50
51
52 int main()
53 {
54 BOOST_THREAD_LOG
55 << boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
56 {
57 try
58 {
59 boost::basic_thread_pool tp;
60 submit_some(tp);
61 }
62 catch (std::exception& ex)
63 {
64 BOOST_THREAD_LOG
65 << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
66 return 1;
67 }
68 catch (...)
69 {
70 BOOST_THREAD_LOG
71 << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
72 return 2;
73 }
74 }
75 BOOST_THREAD_LOG
76 << boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG;
77 return 0;
78 }