Skip to content

Conversation

@huixie90
Copy link
Member

@huixie90 huixie90 commented Dec 7, 2025

not sure why but the current std::barrier's wait implementation is polling on the loop with sleep instead of using the native wait

Before this change, on the CI runner , lost_wakeup.pass.cpp was the slowest test , which uses std::barrier

===
macOS CXX23

Before:

475.32s: llvm-libc++-shared.cfg.in :: std/thread/thread.semaphore/lost_wakeup.pass.cpp

After

10.83s: llvm-libc++-shared.cfg.in :: std/thread/thread.semaphore/lost_wakeup.pass.cpp

===
Linux CXX23:

Before

43.34s: llvm-libc++-shared.cfg.in :: std/thread/thread.semaphore/lost_wakeup.pass.cpp

After:

No longer in the slowest tests list

===
Windows:

Before

80.29s: llvm-libc++-shared-clangcl.cfg.in :: std/thread/thread.semaphore/lost_wakeup.pass.cpp

After

No longer in the slowest test list

This change should also indirectly fix the performance issue of std::barrier described in #123855

@huixie90 huixie90 force-pushed the hxie/barrier_native branch from 6ce071d to cd942d4 Compare December 7, 2025 14:53
@huixie90 huixie90 force-pushed the hxie/barrier_native branch from cd942d4 to 19eaea4 Compare December 7, 2025 14:54
@huixie90 huixie90 marked this pull request as ready for review December 7, 2025 15:03
@huixie90 huixie90 requested a review from a team as a code owner December 7, 2025 15:03
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 7, 2025

@llvm/pr-subscribers-libcxx

Author: Hui (huixie90)

Changes

not sure why but the current std::barrier implementation the wait implementation is polling on the loop instead of using the native wait


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

1 Files Affected:

  • (modified) libcxx/include/barrier (+1-2)
diff --git a/libcxx/include/barrier b/libcxx/include/barrier
index 5f9b471f01741..10d40f32919c8 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -142,8 +142,7 @@ public:
     return __old_phase;
   }
   _LIBCPP_HIDE_FROM_ABI void wait(arrival_token&& __old_phase) const {
-    auto const __test_fn = [this, __old_phase]() -> bool { return __phase_.load(memory_order_acquire) != __old_phase; };
-    std::__libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
+    __phase_.wait(__old_phase, std::memory_order_acquire);
   }
   _LIBCPP_HIDE_FROM_ABI void arrive_and_drop() {
     __expected_adjustment_.fetch_sub(1, memory_order_relaxed);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants