[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.unique_future / wait.pass.cpp
blob4e6b789e45c26d96166c8695f12b62772ca26da3
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: no-threads
10 // UNSUPPORTED: c++03
12 // <future>
14 // class future<R>
16 // void wait() const;
18 #include <cassert>
19 #include <chrono>
20 #include <future>
21 #include <ratio>
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));
29 p.set_value(3);
32 int j = 0;
34 void func3(std::promise<int&> p)
36 std::this_thread::sleep_for(std::chrono::milliseconds(500));
37 j = 5;
38 p.set_value(j);
41 void func5(std::promise<void> p)
43 std::this_thread::sleep_for(std::chrono::milliseconds(500));
44 p.set_value();
47 template <typename T, typename F>
48 void test(F func) {
49 typedef std::chrono::high_resolution_clock Clock;
50 typedef std::chrono::duration<double, std::milli> ms;
52 std::promise<T> p;
53 std::future<T> f = p.get_future();
54 support::make_test_thread(func, std::move(p)).detach();
55 assert(f.valid());
56 f.wait();
57 assert(f.valid());
58 Clock::time_point t0 = Clock::now();
59 f.wait();
60 Clock::time_point t1 = Clock::now();
61 assert(f.valid());
62 assert(t1-t0 < ms(5));
65 int main(int, char**)
67 test<int>(func1);
68 test<int&>(func3);
69 test<void>(func5);
70 return 0;