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 {
15771577 };
15781578
15791579 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;
15811581 }
15821582
15831583 pub fn lock(m: *Mutex, io: Io) Cancelable!void {
1584 const initial_state = m.state.cmpxchgWeak(
1584 const initial_state = m.state.cmpxchgStrong(
15851585 .unlocked,
15861586 .locked_once,
15871587 .acquire,
......@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {
16021602 ///
16031603 /// For a description of cancelation and cancelation points, see `Future.cancel`.
16041604 pub fn lockUncancelable(m: *Mutex, io: Io) void {
1605 const initial_state = m.state.cmpxchgWeak(
1605 const initial_state = m.state.cmpxchgStrong(
16061606 .unlocked,
16071607 .locked_once,
16081608 .acquire,