From fd74c5742d3c8343868516c03a6a0695280744d1 Mon Sep 17 00:00:00 2001 From: hubidubi Date: Fri, 13 Feb 2026 20:39:38 +0100 Subject: [PATCH] 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 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30094 Reviewed-by: Andrew Kelley Co-authored-by: hubidubi Co-committed-by: hubidubi --- lib/std/Io/Threaded.zig | 2 +- lib/std/Io/test.zig | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 60ee5df945..88ec774771 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -1104,7 +1104,7 @@ const Thread = struct { const rc = std.c._umtx_op( @intFromPtr(ptr), @intFromEnum(std.c.UMTX_OP.WAKE_PRIVATE), - @as(c_ulong, max_waiters), + @as(c_ulong, @min(max_waiters, std.math.maxInt(c_int))), 0, // there is no timeout struct 0, // there is no timeout struct pointer ); diff --git a/lib/std/Io/test.zig b/lib/std/Io/test.zig index 70af7a25ee..7b652a495e 100644 --- a/lib/std/Io/test.zig +++ b/lib/std/Io/test.zig @@ -818,10 +818,11 @@ test "Event broadcast" { event: Io.Event = .unset, counter: std.atomic.Value(usize) = std.atomic.Value(usize).init(num_threads), - fn wait(self: *@This()) void { + fn wait(self: *@This()) !void { if (self.counter.fetchSub(1, .acq_rel) == 1) { self.event.set(io); } + try self.event.wait(io); } }; @@ -829,9 +830,9 @@ test "Event broadcast" { start_barrier: Barrier = .{}, finish_barrier: Barrier = .{}, - fn run(self: *@This()) void { - self.start_barrier.wait(); - self.finish_barrier.wait(); + fn run(self: *@This()) !void { + try self.start_barrier.wait(); + try self.finish_barrier.wait(); } }; @@ -841,5 +842,5 @@ test "Event broadcast" { for (&threads) |*t| t.* = try std.Thread.spawn(.{}, Context.run, .{&ctx}); defer for (threads) |t| t.join(); - ctx.run(); + try ctx.run(); }