[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.async / async_race.pass.cpp
blob91a70c2f8b2957171dee3f32c4e826ae33d117ee
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 // template <class F, class... Args>
15 // future<typename result_of<F(Args...)>::type>
16 // async(F&& f, Args&&... args);
18 // template <class F, class... Args>
19 // future<typename result_of<F(Args...)>::type>
20 // async(launch policy, F&& f, Args&&... args);
22 // This test is designed to cause and allow TSAN to detect the race condition
23 // reported in PR23293: https://llvm.org/PR23293
25 #include <future>
26 #include <chrono>
27 #include <thread>
28 #include <memory>
29 #include <cassert>
31 #include "test_macros.h"
33 int f_async() {
34 typedef std::chrono::milliseconds ms;
35 std::this_thread::sleep_for(ms(200));
36 return 42;
39 bool ran = false;
41 int f_deferred() {
42 ran = true;
43 return 42;
46 void test_each() {
48 std::future<int> f = std::async(f_async);
49 int const result = f.get();
50 assert(result == 42);
53 std::future<int> f = std::async(std::launch::async, f_async);
54 int const result = f.get();
55 assert(result == 42);
58 ran = false;
59 std::future<int> f = std::async(std::launch::deferred, f_deferred);
60 assert(ran == false);
61 int const result = f.get();
62 assert(ran == true);
63 assert(result == 42);
67 int main(int, char**) {
68 for (int i=0; i < 25; ++i) test_each();
70 return 0;