[libcxx-commits] [libcxx] Fix async test (PR #146240)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 28 14:01:01 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Eric (EricWF)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/146240.diff


1 Files Affected:

- (modified) libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp (+2-2) 


``````````diff
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/146240


More information about the libcxx-commits mailing list