1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
14 // class shared_future<R>
16 // const R& shared_future::get();
17 // R& shared_future<R&>::get();
18 // void shared_future<void>::get();
23 #include "make_test_thread.h"
24 #include "test_macros.h"
26 void func1(std::promise
<int> p
)
28 std::this_thread::sleep_for(std::chrono::milliseconds(500));
32 void func2(std::promise
<int> p
)
34 std::this_thread::sleep_for(std::chrono::milliseconds(500));
35 p
.set_exception(std::make_exception_ptr(3));
40 void func3(std::promise
<int&> p
)
42 std::this_thread::sleep_for(std::chrono::milliseconds(500));
47 void func4(std::promise
<int&> p
)
49 std::this_thread::sleep_for(std::chrono::milliseconds(500));
50 p
.set_exception(std::make_exception_ptr(3.5));
53 void func5(std::promise
<void> p
)
55 std::this_thread::sleep_for(std::chrono::milliseconds(500));
59 void func6(std::promise
<void> p
)
61 std::this_thread::sleep_for(std::chrono::milliseconds(500));
62 p
.set_exception(std::make_exception_ptr('c'));
71 std::shared_future
<T
> f
= p
.get_future();
72 support::make_test_thread(func1
, std::move(p
)).detach();
77 #ifndef TEST_HAS_NO_EXCEPTIONS
80 std::shared_future
<T
> f
= p
.get_future();
81 support::make_test_thread(func2
, std::move(p
)).detach();
100 std::shared_future
<T
> f
= p
.get_future();
101 support::make_test_thread(func3
, std::move(p
)).detach();
103 assert(f
.get() == 5);
106 #ifndef TEST_HAS_NO_EXCEPTIONS
109 std::shared_future
<T
> f
= p
.get_future();
110 support::make_test_thread(func4
, std::move(p
)).detach();
114 assert(f
.get() == 3);
129 std::shared_future
<T
> f
= p
.get_future();
130 support::make_test_thread(func5
, std::move(p
)).detach();
135 #ifndef TEST_HAS_NO_EXCEPTIONS
138 std::shared_future
<T
> f
= p
.get_future();
139 support::make_test_thread(func6
, std::move(p
)).detach();