]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/thread_pool.cpp
update sources to v12.2.3
[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 4
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/assert.hpp>
19 #include <string>
20
21 #ifdef BOOST_MSVC
22 #pragma warning(disable: 4127) // conditional expression is constant
23 #endif
24
25 void p1()
26 {
27 BOOST_THREAD_LOG
28 << boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG;
29 }
30
31 void p2()
32 {
33 BOOST_THREAD_LOG
34 << boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG;
35 }
36
37 void submit_some(boost::basic_thread_pool& tp) {
38 tp.submit(&p1);
39 tp.submit(&p2);
40 tp.submit(&p1);
41 tp.submit(&p2);
42 tp.submit(&p1);
43 tp.submit(&p2);
44 tp.submit(&p1);
45 tp.submit(&p2);
46 tp.submit(&p1);
47 tp.submit(&p2);
48 }
49
50
51 int main()
52 {
53 BOOST_THREAD_LOG
54 << boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
55 {
56 try
57 {
58 boost::basic_thread_pool tp;
59 submit_some(tp);
60 }
61 catch (std::exception& ex)
62 {
63 BOOST_THREAD_LOG
64 << "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
65 return 1;
66 }
67 catch (...)
68 {
69 BOOST_THREAD_LOG
70 << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
71 return 2;
72 }
73 }
74 BOOST_THREAD_LOG
75 << boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG;
76 return 0;
77 }