authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-03-10 09:17:42+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-03-10 10:05:09+01:00
log048e38624e1b7c1ad140e253f1e5e7c868658089
tree64334f44969c34a21d9738d1f8023d7ee15729a7
parentcfe5c88ad6081e284d0caf36cf8d7e80fe39b676
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

fix: use cmpxchgStrong in `Io.Mutex`

* `cmpxchgWeak` can fail spuriously on LL/SC architectures and `tryLock` would invalidly return false in those cases.

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/Io.zig+3-3
...@@ -1577,11 +1577,11 @@ pub const Mutex = extern struct {...@@ -1577,11 +1577,11 @@ pub const Mutex = extern struct {
1577 };1577 };
15781578
1579 pub fn tryLock(m: *Mutex) bool {1579 pub fn tryLock(m: *Mutex) bool {
1580 return m.state.cmpxchgWeak(.unlocked, .locked_once, .acquire, .monotonic) == null;1580 return m.state.cmpxchgStrong(.unlocked, .locked_once, .acquire, .monotonic) == null;
1581 }1581 }
15821582
1583 pub fn lock(m: *Mutex, io: Io) Cancelable!void {1583 pub fn lock(m: *Mutex, io: Io) Cancelable!void {
1584 const initial_state = m.state.cmpxchgWeak(1584 const initial_state = m.state.cmpxchgStrong(
1585 .unlocked,1585 .unlocked,
1586 .locked_once,1586 .locked_once,
1587 .acquire,1587 .acquire,
...@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {...@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {
1602 ///1602 ///
1603 /// For a description of cancelation and cancelation points, see `Future.cancel`.1603 /// For a description of cancelation and cancelation points, see `Future.cancel`.
1604 pub fn lockUncancelable(m: *Mutex, io: Io) void {1604 pub fn lockUncancelable(m: *Mutex, io: Io) void {
1605 const initial_state = m.state.cmpxchgWeak(1605 const initial_state = m.state.cmpxchgStrong(
1606 .unlocked,1606 .unlocked,
1607 .locked_once,1607 .locked_once,
1608 .acquire,1608 .acquire,