authorgravatar for hubidubi@noreply.codeberg.orghubidubi <hubidubi@noreply.codeberg.org> 2026-02-13 20:39:38+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-13 20:39:38+01:00
logfd74c5742d3c8343868516c03a6a0695280744d1
tree0988ebfa90fe3da65d12be7d682a7dc797c925a8
parentdbfe34167de6b2a3a46ee4aff8f016c5afda7ccf

std.Io.Threaded: fix FreeBSD Futex max_waiters (#30094)

On FreeBSD, the maximum waiters should be Cs INT_MAX instead of the maximum of a u32. Waiting for the Io.Event in the broadcast test triggers this bug. Resolves #30715 Co-authored-by: Simon Galli <hubi@hubidubi.net> Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30094 Reviewed-by: Andrew Kelley <andrew@ziglang.org> Co-authored-by: hubidubi <hubidubi@noreply.codeberg.org> Co-committed-by: hubidubi <hubidubi@noreply.codeberg.org>

2 files changed, 7 insertions(+), 6 deletions(-)

lib/std/Io/Threaded.zig+1-1
......@@ -1104,7 +1104,7 @@ const Thread = struct {
11041104 const rc = std.c._umtx_op(
11051105 @intFromPtr(ptr),
11061106 @intFromEnum(std.c.UMTX_OP.WAKE_PRIVATE),
1107 @as(c_ulong, max_waiters),
1107 @as(c_ulong, @min(max_waiters, std.math.maxInt(c_int))),
11081108 0, // there is no timeout struct
11091109 0, // there is no timeout struct pointer
11101110 );
lib/std/Io/test.zig+6-5
......@@ -818,10 +818,11 @@ test "Event broadcast" {
818818 event: Io.Event = .unset,
819819 counter: std.atomic.Value(usize) = std.atomic.Value(usize).init(num_threads),
820820
821 fn wait(self: *@This()) void {
821 fn wait(self: *@This()) !void {
822822 if (self.counter.fetchSub(1, .acq_rel) == 1) {
823823 self.event.set(io);
824824 }
825 try self.event.wait(io);
825826 }
826827 };
827828
......@@ -829,9 +830,9 @@ test "Event broadcast" {
829830 start_barrier: Barrier = .{},
830831 finish_barrier: Barrier = .{},
831832
832 fn run(self: *@This()) void {
833 self.start_barrier.wait();
834 self.finish_barrier.wait();
833 fn run(self: *@This()) !void {
834 try self.start_barrier.wait();
835 try self.finish_barrier.wait();
835836 }
836837 };
837838
......@@ -841,5 +842,5 @@ test "Event broadcast" {
841842 for (&threads) |*t| t.* = try std.Thread.spawn(.{}, Context.run, .{&ctx});
842843 defer for (threads) |t| t.join();
843844
844 ctx.run();
845 try ctx.run();
845846}