]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/future_unwrap.cpp
1 // Copyright (C) 2012-2013 Vicente Botet
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)
6 #include <boost/config.hpp>
7 #if ! defined BOOST_NO_CXX11_DECLTYPE
8 #define BOOST_RESULT_OF_USE_DECLTYPE
11 #define BOOST_THREAD_VERSION 4
12 //#define BOOST_THREAD_USES_LOG
13 #define BOOST_THREAD_USES_LOG_THREAD_ID
15 #include <boost/thread/detail/log.hpp>
16 #include <boost/thread/future.hpp>
17 #include <boost/assert.hpp>
21 #if defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
24 #pragma warning(disable: 4127) // conditional expression is constant
29 BOOST_THREAD_LOG
<< "P1" << BOOST_THREAD_END_LOG
;
33 boost::future
<int> p2()
35 BOOST_THREAD_LOG
<< "<P2" << BOOST_THREAD_END_LOG
;
36 boost::future
<int> f1
= boost::async(boost::launch::async
, &p1
);
37 BOOST_THREAD_LOG
<< "P2>" << BOOST_THREAD_END_LOG
;
38 return boost::move(f1
);
43 const int number_of_tests
= 100;
44 BOOST_THREAD_LOG
<< "<MAIN" << BOOST_THREAD_END_LOG
;
45 for (int i
=0; i
< number_of_tests
; i
++)
49 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
51 boost::future
<int> inner_future
= boost::async(boost::launch::async
, &p2
).unwrap();
53 int ii
= inner_future
.get();
54 BOOST_THREAD_LOG
<< "ii= "<< ii
<< "" << BOOST_THREAD_END_LOG
;
58 boost::future
<boost::future
<int> > outer_future
= boost::async(boost::launch::async
, &p2
);
59 boost::future
<int> inner_future
= outer_future
.unwrap();
61 int ii
= inner_future
.get();
62 BOOST_THREAD_LOG
<< "ii= "<< ii
<< "" << BOOST_THREAD_END_LOG
;
65 boost::future
<boost::future
<int> > outer_future
= boost::async(boost::launch::async
, &p2
);
66 boost::future
<int> inner_future
= outer_future
.unwrap();
67 int ii
= inner_future
.get();
68 BOOST_THREAD_LOG
<< "ii= "<< ii
<< "" << BOOST_THREAD_END_LOG
;
71 catch (std::exception
& ex
)
73 std::cout
<< "ERRORRRRR "<<ex
.what() << "" << std::endl
;
74 BOOST_THREAD_LOG
<< "ERRORRRRR "<<ex
.what() << "" << BOOST_THREAD_END_LOG
;
79 std::cout
<< " ERRORRRRR exception thrown" << std::endl
;
80 BOOST_THREAD_LOG
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG
;
83 BOOST_THREAD_LOG
<< "MAIN>" << BOOST_THREAD_END_LOG
;