brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 7384a19 Raw
43 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++0311 12// This test uses std::atomic interfaces that are only available in C++2013// UNSUPPORTED: c++11, c++14, c++1714 15// Make sure that the `future` destructor keeps the data alive until the thread finished. This test fails by triggering16// TSan. It may not be observable by normal means.17 18// See https://github.com/llvm/llvm-project/pull/125433#issuecomment-2703618927 for more details.19 20#include <atomic>21#include <future>22#include <mutex>23#include <condition_variable>24#include <thread>25 26std::mutex mux;27 28int main(int, char**) {29  std::condition_variable cond;30  std::unique_lock lock(mux);31  auto v = std::async(std::launch::async, [&cond, value = 1]() mutable {32    std::unique_lock thread_lock(mux);33    cond.notify_all();34    thread_lock.unlock();35 36    value = 4;37    (void)value;38  });39  cond.wait(lock);40 41  return 0;42}43