[libcxx-commits] [libcxx] 4aaab69 - [libc++] Fix wait_on_destruct.pass.cpp hanging sometimes (#146240)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 30 08:54:16 PDT 2025
Author: Eric
Date: 2025-06-30T11:54:12-04:00
New Revision: 4aaab693148e3f98923f8f77ff02c665e9d25d10
URL: https://github.com/llvm/llvm-project/commit/4aaab693148e3f98923f8f77ff02c665e9d25d10
DIFF: https://github.com/llvm/llvm-project/commit/4aaab693148e3f98923f8f77ff02c665e9d25d10.diff
LOG: [libc++] Fix wait_on_destruct.pass.cpp hanging sometimes (#146240)
This test was deadlocking on my machine.
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.~
I've addressed the issues with the `in_async` by switching to a
condition variable instead, since my first attempt at fixing this with
`in_async` wasn't sufficient.
Added:
Modified:
libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp
Removed:
################################################################################
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..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
@@ -20,22 +20,24 @@
#include <atomic>
#include <future>
#include <mutex>
+#include <condition_variable>
+#include <thread>
+
std::mutex mux;
int main(int, char**) {
- using namespace std::chrono_literals;
+ std::condition_variable cond;
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);
+ auto v = std::async(std::launch::async, [&cond, value = 1]() mutable {
+ std::unique_lock thread_lock(mux);
+ cond.notify_all();
+ thread_lock.unlock();
+
value = 4;
(void)value;
});
- in_async.wait(true);
- lock.unlock();
+ cond.wait(lock);
return 0;
}
More information about the libcxx-commits
mailing list