authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-03-21 01:11:26+01:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-03-21 03:00:50+01:00
logb6f99a59a3270baf6bfd8e3152e58f1c47455d08
tree34becf7fc3f126947da0ab54c8987df4f2b3ffb6
parente938344100da959308aa27dee1295e5ce02efc30

std.Progress: use `cmpxchgStrong` instead of `cmpxchgWeak` for locking/unlocking IPC

The `cmpxchgWeak` in `setIpcFile` could lead to the IPC file not being set even though there's still a slot available because one or more slots were spuriously skipped. The `cmpxcheWeak` in `serialize` could lead to an unused IPC slot not being locked and used even though it could be.

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

lib/std/Progress.zig+2-2
...@@ -450,7 +450,7 @@ pub const Node = struct {...@@ -450,7 +450,7 @@ pub const Node = struct {
450 const ipc = @atomicLoad(Ipc, ipc_ptr, .monotonic);450 const ipc = @atomicLoad(Ipc, ipc_ptr, .monotonic);
451 if (ipc.locked or ipc.valid) continue;451 if (ipc.locked or ipc.valid) continue;
452 const generation = ipc.generation +% 1;452 const generation = ipc.generation +% 1;
453 if (@cmpxchgWeak(453 if (@cmpxchgStrong(
454 Ipc,454 Ipc,
455 ipc_ptr,455 ipc_ptr,
456 ipc,456 ipc,
...@@ -1133,7 +1133,7 @@ fn serialize(io: Io, serialized_buffer: *Serialized.Buffer) !Serialized {...@@ -1133,7 +1133,7 @@ fn serialize(io: Io, serialized_buffer: *Serialized.Buffer) !Serialized {
1133 const ipc_data = &serialized_buffer.ipc_data[ipc_index.slot];1133 const ipc_data = &serialized_buffer.ipc_data[ipc_index.slot];
1134 state: switch (ipc_data.state) {1134 state: switch (ipc_data.state) {
1135 .unused => {1135 .unused => {
1136 if (@cmpxchgWeak(1136 if (@cmpxchgStrong(
1137 Ipc,1137 Ipc,
1138 ipc,1138 ipc,
1139 .{ .locked = false, .valid = true, .generation = ipc_index.generation },1139 .{ .locked = false, .valid = true, .generation = ipc_index.generation },