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 #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(); - 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; }