]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/futures/shared_future/get_pass.cpp
1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Copyright (C) 2011 Vicente J. Botet Escriba
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15 // <boost/thread/shared_future.hpp>
17 // class shared_future<R>
19 // const R& shared_future::get();
20 // R& shared_future<R&>::get();
21 // void shared_future<void>::get();
22 //#define BOOST_THREAD_VERSION 3
23 #define BOOST_THREAD_VERSION 4
25 #include <boost/thread/future.hpp>
26 #include <boost/thread/thread.hpp>
27 #include <boost/detail/lightweight_test.hpp>
29 #if defined BOOST_THREAD_USES_CHRONO
36 wrap(T
const& v
) : value(v
){}
42 exception_ptr
make_exception_ptr(T v
) {
43 return copy_exception(wrap
<T
>(v
));
47 void func1(boost::promise
<int> p
)
49 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
53 void func2(boost::promise
<int> p
)
55 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
56 p
.set_exception(boost::make_exception_ptr(3));
61 void func3(boost::promise
<int&> p
)
63 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
68 void func4(boost::promise
<int&> p
)
70 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
71 p
.set_exception(boost::make_exception_ptr(3.5));
74 void func5(boost::promise
<void> p
)
76 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
80 void func6(boost::promise
<void> p
)
82 boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
83 p
.set_exception(boost::make_exception_ptr(4));
93 boost::shared_future
<T
> f((p
.get_future()));
94 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
95 boost::thread(func1
, boost::move(p
)).detach();
99 BOOST_TEST(f
.valid());
100 BOOST_TEST(f
.get() == 3);
101 BOOST_TEST(f
.valid());
105 boost::shared_future
<T
> f((p
.get_future()));
106 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
107 boost::thread(func2
, boost::move(p
)).detach();
109 p
.set_exception(boost::make_exception_ptr(3));
113 BOOST_TEST(f
.valid());
114 BOOST_TEST(f
.get() == 3);
117 catch (boost::wrap
<int> const& i
)
119 BOOST_TEST(i
.value
== 3);
125 BOOST_TEST(f
.valid());
132 boost::shared_future
<T
> f((p
.get_future()));
133 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
134 boost::thread(func3
, boost::move(p
)).detach();
139 BOOST_TEST(f
.valid());
140 BOOST_TEST(f
.get() == 5);
141 BOOST_TEST(f
.valid());
145 boost::shared_future
<T
> f((p
.get_future()));
146 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
147 boost::thread(func4
, boost::move(p
)).detach();
149 p
.set_exception(boost::make_exception_ptr(3.5));
153 BOOST_TEST(f
.valid());
154 BOOST_TEST(f
.get() == 3);
157 catch (boost::wrap
<double> const& i
)
159 BOOST_TEST(i
.value
== 3.5);
161 BOOST_TEST(f
.valid());
168 boost::shared_future
<T
> f((p
.get_future()));
169 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
170 boost::thread(func5
, boost::move(p
)).detach();
174 BOOST_TEST(f
.valid());
176 BOOST_TEST(f
.valid());
180 boost::shared_future
<T
> f((p
.get_future()));
181 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
182 boost::thread(func6
, boost::move(p
)).detach();
184 p
.set_exception(boost::make_exception_ptr(4));
188 BOOST_TEST(f
.valid());
192 catch (boost::wrap
<int> const& i
)
194 BOOST_TEST(i
.value
== 4);
200 BOOST_TEST(f
.valid());
203 return boost::report_errors();
207 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"