Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / thread / futures / futures.async / async_race.38682.pass.cpp
blobf6bc1286eb394d5503ea2e27d0662fbc06994803
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 // This test requires the fix for http://llvm.org/PR38682 (616ef1863fae). We mark the
13 // test as UNSUPPORTED instead of XFAIL because the test doesn't fail consistently.
14 // UNSUPPORTED: using-built-library-before-llvm-10
16 // This test is designed to cause and allow TSAN to detect a race condition
17 // in std::async, as reported in https://llvm.org/PR38682.
19 #include <cassert>
20 #include <functional>
21 #include <future>
22 #include <numeric>
23 #include <vector>
25 #include "test_macros.h"
28 static int worker(std::vector<int> const& data) {
29 return std::accumulate(data.begin(), data.end(), 0);
32 static int& worker_ref(int& i) { return i; }
34 static void worker_void() { }
36 int main(int, char**) {
37 // future<T>
39 std::vector<int> const v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
40 for (int i = 0; i != 20; ++i) {
41 std::future<int> fut = std::async(std::launch::async, worker, v);
42 int answer = fut.get();
43 assert(answer == 55);
47 // future<T&>
49 for (int i = 0; i != 20; ++i) {
50 std::future<int&> fut = std::async(std::launch::async, worker_ref, std::ref(i));
51 int& answer = fut.get();
52 assert(answer == i);
56 // future<void>
58 for (int i = 0; i != 20; ++i) {
59 std::future<void> fut = std::async(std::launch::async, worker_void);
60 fut.get();
64 return 0;