[libcxx-commits] [libcxx] [libc++] Don't try to wait on a thread that hasn't started in std::async, take 2 (PR #130145)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 25 08:31:55 PDT 2025
================
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
+
+// This test uses std::atomic interfaces that are only available in C++20
+// UNSUPPORTED: c++11, c++14, c++17
+
+// Make sure that the `future` destructor keeps the data alive until the thread finished. This test fails by triggering
+// TSan. It may not be observable by normal means.
+
+#include <atomic>
+#include <future>
+#include <mutex>
+
+std::mutex mux;
+
+int main() {
+ using namespace std::chrono_literals;
+ std::unique_lock lock(mux);
+ std::atomic<bool> in_async = false;
+ auto v = std::async(std::launch::async, [&in_async, value = 1]() mutable {
+ in_async = true;
+ in_async.notify_all();
+ std::scoped_lock thread_lock(mux);
+ value = 4;
+ (void)value;
+ });
+ in_async.wait(true);
+ lock.unlock();
+}
----------------
ldionne wrote:
`return 0;`
https://github.com/llvm/llvm-project/pull/130145
More information about the libcxx-commits
mailing list