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>
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));
34 void func3(std::promise
<int&> p
)
36 std::this_thread::sleep_for(std::chrono::milliseconds(500));
41 void func5(std::promise
<void> p
)
43 std::this_thread::sleep_for(std::chrono::milliseconds(500));
49 typedef std::chrono::high_resolution_clock Clock
;
50 typedef std::chrono::duration
<double, std::milli
> ms
;
54 std::shared_future
<T
> f
= p
.get_future();
55 support::make_test_thread(func1
, std::move(p
)).detach();
59 Clock::time_point t0
= Clock::now();
61 Clock::time_point t1
= Clock::now();
63 assert(t1
-t0
< ms(5));
68 std::shared_future
<T
> f
= p
.get_future();
69 support::make_test_thread(func3
, std::move(p
)).detach();
73 Clock::time_point t0
= Clock::now();
75 Clock::time_point t1
= Clock::now();
77 assert(t1
-t0
< ms(5));
82 std::shared_future
<T
> f
= p
.get_future();
83 support::make_test_thread(func5
, std::move(p
)).detach();
87 Clock::time_point t0
= Clock::now();
89 Clock::time_point t1
= Clock::now();
91 assert(t1
-t0
< ms(5));