From 06a816ea63c9338f80f9ea5a77bfc7e1c38f1143 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 28 Jun 2025 16:57:38 -0400 Subject: [PATCH 1/3] Fix async test It seems to me the intention of `in_async.wait(...)` was to wait for the value to be set to true, which requires a call of `wait(false)` (waits if value matches argument). As a drive by change scoped_lock to unique_lock, since there shouldn't be any functional difference between the two in this test. Alternatively, the test could be written with a condition variable directly. --- .../thread/futures/futures.async/wait_on_destruct.pass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp index 8260ec3dfcaf4..6ab9f1d0b1afb 100644 --- a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp @@ -30,11 +30,11 @@ int main(int, char**) { 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); + std::unique_lock thread_lock(mux); value = 4; (void)value; }); - in_async.wait(true); + in_async.wait(false); lock.unlock(); return 0; From ca83b46049458067c11012fbbdb5f10bf751d44b Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 28 Jun 2025 17:07:21 -0400 Subject: [PATCH 2/3] Use condition variable approach instead --- .../futures.async/wait_on_destruct.pass.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp index 6ab9f1d0b1afb..9716ec11ad495 100644 --- a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp @@ -20,22 +20,25 @@ #include #include #include +#include +#include +#include std::mutex mux; int main(int, char**) { - using namespace std::chrono_literals; + std::condition_variable cond; std::unique_lock lock(mux); - std::atomic in_async = false; - auto v = std::async(std::launch::async, [&in_async, value = 1]() mutable { - in_async = true; - in_async.notify_all(); + auto v = std::async(std::launch::async, [&cond, value = 1]() mutable { std::unique_lock thread_lock(mux); + cond.notify_all(); + thread_lock.unlock(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + value = 4; (void)value; }); - in_async.wait(false); - lock.unlock(); + cond.wait(lock); return 0; } From e7facf2742855c76f6ba4d9283250fda92171950 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 30 Jun 2025 11:53:38 -0400 Subject: [PATCH 3/3] Update wait_on_destruct.pass.cpp Remove the sleep as requested. --- .../std/thread/futures/futures.async/wait_on_destruct.pass.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp index 9716ec11ad495..d2964e02257d2 100644 --- a/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp +++ b/libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp @@ -22,7 +22,7 @@ #include #include #include -#include + std::mutex mux; @@ -33,7 +33,6 @@ int main(int, char**) { std::unique_lock thread_lock(mux); cond.notify_all(); thread_lock.unlock(); - std::this_thread::sleep_for(std::chrono::seconds(1)); value = 4; (void)value;