From 048e38624e1b7c1ad140e253f1e5e7c868658089 Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Tue, 10 Mar 2026 09:17:42 +0100 Subject: [PATCH] fix: use cmpxchgStrong in `Io.Mutex` * `cmpxchgWeak` can fail spuriously on LL/SC architectures and `tryLock` would invalidly return false in those cases. --- lib/std/Io.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/Io.zig b/lib/std/Io.zig index 87f342f640..8d51f649e3 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -1577,11 +1577,11 @@ pub const Mutex = extern struct { }; pub fn tryLock(m: *Mutex) bool { - return m.state.cmpxchgWeak(.unlocked, .locked_once, .acquire, .monotonic) == null; + return m.state.cmpxchgStrong(.unlocked, .locked_once, .acquire, .monotonic) == null; } pub fn lock(m: *Mutex, io: Io) Cancelable!void { - const initial_state = m.state.cmpxchgWeak( + const initial_state = m.state.cmpxchgStrong( .unlocked, .locked_once, .acquire, @@ -1602,7 +1602,7 @@ pub const Mutex = extern struct { /// /// For a description of cancelation and cancelation points, see `Future.cancel`. pub fn lockUncancelable(m: *Mutex, io: Io) void { - const initial_state = m.state.cmpxchgWeak( + const initial_state = m.state.cmpxchgStrong( .unlocked, .locked_once, .acquire,