[libcxx-commits] [libcxx] [libc++] Fix std::future not waiting until the thread is finished to clean up (PR #130145)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 30 02:35:45 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions ,cpp -- libcxx/test/std/thread/futures/futures.async/wait_on_destruct.pass.cpp libcxx/include/future
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/future b/libcxx/include/future
index 197830809..2edf46a54 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -1829,16 +1829,16 @@ template <class _Rp, class _Fp>
 _LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f) {
   unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h(
       new __async_assoc_state<_Rp, _Fp>(std::forward<_Fp>(__f)));
-#if _LIBCPP_HAS_EXCEPTIONS
+#    if _LIBCPP_HAS_EXCEPTIONS
   try {
-#endif
+#    endif
     std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
-#if _LIBCPP_HAS_EXCEPTIONS
+#    if _LIBCPP_HAS_EXCEPTIONS
   } catch (...) {
     __h->__make_ready();
     throw;
   }
-#endif
+#    endif
   return future<_Rp>(__h.get());
 }
 
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 b33d38736..bb891313d 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
@@ -25,7 +25,7 @@ int main() {
   using namespace std::chrono_literals;
   std::scoped_lock lock(mux);
   std::atomic<bool> in_async = false;
-  auto v = std::async(std::launch::async, [&in_async, value = 1]() mutable {
+  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);

``````````

</details>


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


More information about the libcxx-commits mailing list