[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / thread / futures / futures.unique_future / wait.pass.cpp
blob712ee3b9b4a15c7025c4d039c535af20d36ca9e0
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: libcpp-has-no-threads
10 // UNSUPPORTED: c++03
12 // <future>
14 // class future<R>
16 // void wait() const;
18 #include <future>
19 #include <cassert>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 void func1(std::promise<int> p)
26 std::this_thread::sleep_for(std::chrono::milliseconds(500));
27 p.set_value(3);
30 int j = 0;
32 void func3(std::promise<int&> p)
34 std::this_thread::sleep_for(std::chrono::milliseconds(500));
35 j = 5;
36 p.set_value(j);
39 void func5(std::promise<void> p)
41 std::this_thread::sleep_for(std::chrono::milliseconds(500));
42 p.set_value();
45 template <typename T, typename F>
46 void test(F func) {
47 typedef std::chrono::high_resolution_clock Clock;
48 typedef std::chrono::duration<double, std::milli> ms;
50 std::promise<T> p;
51 std::future<T> f = p.get_future();
52 support::make_test_thread(func, std::move(p)).detach();
53 assert(f.valid());
54 f.wait();
55 assert(f.valid());
56 Clock::time_point t0 = Clock::now();
57 f.wait();
58 Clock::time_point t1 = Clock::now();
59 assert(f.valid());
60 assert(t1-t0 < ms(5));
63 int main(int, char**)
65 test<int>(func1);
66 test<int&>(func3);
67 test<void>(func5);
68 return 0;