Rust apparently uses yield on arm32, and isb (instruction sync barrier) on aarch64, as yield is effectively a NOP (although it could be implemented to free up pipeline slots, SMT switch, or signal), while isb (with optional sy operand) is more like pause on x86_64:

        https://stackoverflow.com/a/70811680

https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/yield

https://developer.arm.com/documentation/ddi0596/2021-06/Base-Instructions/ISB--Instruction-Synchronization-Barrier-

https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/intrinsics/intrinsics-for-sse2/miscellaneous-functions-and-intrinsics/pause-intrinsic.html

On 2025-06-12 07:17, Radek Barton via Cygwin-patches wrote:
This patch implements pause for spin locks at two places in the codebase: 
winsup/cygwin/local_includes/cygtls.h and winsup/cygwin/thread.cc 
b/winsup/cygwin/thread.cc.
---
 From 0f82052a8c60811f784bbc76f6df1e0d9a971947 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Barto=C5=88?= <[email protected]>
Date: Thu, 5 Jun 2025 12:41:37 +0200
Subject: [PATCH] Cygwin: implement spinlock pause for AArch64

---
  winsup/cygwin/local_includes/cygtls.h | 4 +++-
  winsup/cygwin/thread.cc               | 4 ++++
  2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/local_includes/cygtls.h 
b/winsup/cygwin/local_includes/cygtls.h
index 4698352ae..74ff92971 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -242,8 +242,10 @@ public: /* Do NOT remove this public: line, it's a marker 
for gentls_offsets. */
    {
      while (InterlockedExchange (&stacklock, 1))
        {
-#ifdef __x86_64__
+#if defined(__x86_64__)
        __asm__ ("pause");
+#elif defined(__aarch64__)
+       __asm__ ("yield");
  #else
  #error unimplemented for this target
  #endif
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index fea6079b8..a504e13b5 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -1968,7 +1968,11 @@ pthread_spinlock::lock ()
        else if (spins < FAST_SPINS_LIMIT)
          {
            ++spins;
+#if defined(__x86_64__)
            __asm__ volatile ("pause":::);
+#elif defined(__aarch64__)
+          __asm__ volatile ("yield":::);
+#endif
          }
        else
        {


--
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                -- Antoine de Saint-Exupéry

Reply via email to