From 29ccf67f774866c990e42a1b68817dd09ea30f6c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 21 Apr 2026 10:41:56 -0700 Subject: [PATCH] rustc_thread_pool: Make `CoreLatch::set` use `SeqCst` instead of `AcqRel` Every other modification of this variable uses `SeqCst`, which is justified in the sleep README. This particular choice of `AcqRel` was not discussed during its addition in rayon-rs/rayon#746, nor rayon-rs/rfcs#5, so I suspect was simply an oversight from earlier development. We probably do want this to participate in the same sequential consistency. The only other ordering difference is `CoreLatch::probe`'s load with `Acquire`, which should be fine because this doesn't need consistency with the sleep counters. See also rayon-rs/rayon#1297. As I commented there, I think in practice this would be quite rare to cause any problems, but it *could* be a source of non-deterministic bugs on targets with weak memory ordering. --- compiler/rustc_thread_pool/src/latch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_thread_pool/src/latch.rs b/compiler/rustc_thread_pool/src/latch.rs index 58dabaf35c005..29c85146e4f17 100644 --- a/compiler/rustc_thread_pool/src/latch.rs +++ b/compiler/rustc_thread_pool/src/latch.rs @@ -117,7 +117,7 @@ impl CoreLatch { /// latch code. #[inline] unsafe fn set(this: *const Self) -> bool { - let old_state = unsafe { (*this).state.swap(SET, Ordering::AcqRel) }; + let old_state = unsafe { (*this).state.swap(SET, Ordering::SeqCst) }; old_state == SLEEPING }