From 048e38624e1b7c1ad140e253f1e5e7c868658089 Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Tue, 10 Mar 2026 09:17:42 +0100 Subject: [PATCH 1/4] 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 87f342f640316343440e5f93e2c1924b81a51c6e..8d51f649e3e79180860e02c2e4930e975cce7e33 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, -- 2.54.0 From 7c2699bed2bf929eb116aa6b1a8e0ed1fd66240b Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Tue, 10 Mar 2026 10:05:25 +0100 Subject: [PATCH 2/4] Revert "std.Io.RwLock: disable `smoke test` on any aarch64 target" This reverts commit cfe5c88ad6081e284d0caf36cf8d7e80fe39b676. --- lib/std/Io/RwLock.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/Io/RwLock.zig b/lib/std/Io/RwLock.zig index 586a94af034d50ed0d632f97abaa29ff29b280b5..fff958efe9a8db7d3d6c2c03349acbfc270453bf 100644 --- a/lib/std/Io/RwLock.zig +++ b/lib/std/Io/RwLock.zig @@ -114,7 +114,7 @@ test "internal state" { } test "smoke test" { - if (builtin.target.cpu.arch.isAARCH64()) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31393 + if (builtin.target.cpu.arch.isAARCH64() and builtin.target.os.tag == .netbsd) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31393 const io = testing.io; -- 2.54.0 From 2370dc886cf4bc919d912ea3c0a564f71675fd2e Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Tue, 10 Mar 2026 10:05:40 +0100 Subject: [PATCH 3/4] Revert "std.Io.RwLock: disable `smoke test` on aarch64-netbsd" This reverts commit 0ae1c6b54acf112c7bbcc63a19f7ad8fa9842d2a. --- lib/std/Io/RwLock.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/std/Io/RwLock.zig b/lib/std/Io/RwLock.zig index fff958efe9a8db7d3d6c2c03349acbfc270453bf..7be4f026e16c150feef443286315567add6bf69c 100644 --- a/lib/std/Io/RwLock.zig +++ b/lib/std/Io/RwLock.zig @@ -114,8 +114,6 @@ test "internal state" { } test "smoke test" { - if (builtin.target.cpu.arch.isAARCH64() and builtin.target.os.tag == .netbsd) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31393 - const io = testing.io; var rl: Io.RwLock = .init; -- 2.54.0 From d70bd0b37eafb82e3020f163ebcbaa2c13791e75 Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Tue, 10 Mar 2026 19:46:56 +0100 Subject: [PATCH 4/4] fix: use `cmpxchgStrong` in `std.atomic.Mutex` * same reason as 048e38624e1b7c1ad140e253f1e5e7c868658089 --- lib/std/atomic.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig index 0040dbf735eeaabad5c5d532663757bfb5de5491..89f22a89ccc72b1a962a5f781a7c9692b6174a6c 100644 --- a/lib/std/atomic.zig +++ b/lib/std/atomic.zig @@ -509,7 +509,7 @@ pub const Mutex = enum(u8) { locked, pub fn tryLock(m: *Mutex) bool { - return @cmpxchgWeak(Mutex, m, .unlocked, .locked, .acquire, .monotonic) == null; + return @cmpxchgStrong(Mutex, m, .unlocked, .locked, .acquire, .monotonic) == null; } pub fn unlock(m: *Mutex) void { -- 2.54.0