From 54eb03cbf61a5c5fdee29c0f45cca824e13d6af8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 20 Feb 2026 16:42:37 -0800 Subject: [PATCH] std.Io.Select: remove "outstanding" field it is not fundamentally part of this abstraction --- lib/std/Io.zig | 8 -------- lib/std/crypto/kangarootwelve.zig | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/std/Io.zig b/lib/std/Io.zig index ff58bb400e49697a6557ce45ce451bad72a76973..6d8fbc45365ed90ed70e65141390dfc8b9b58240 100644 --- a/lib/std/Io.zig +++ b/lib/std/Io.zig @@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type { io: Io, group: Group, queue: Queue(U), - outstanding: usize, const S = @This(); @@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type { .io = io, .queue = .init(buffer), .group = .init, - .outstanding = 0, }; } @@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type { } }; const context: Context = .{ .select = s, .args = args }; - _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic); s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); } @@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type { }; const context: Context = .{ .select = s, .args = args }; try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start); - _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic); } /// Blocks until another task of the select finishes. /// - /// Asserts there is at least one more `outstanding` task. - /// /// Not threadsafe. pub fn await(s: *S) Cancelable!U { - s.outstanding -= 1; return s.queue.getOne(s.io) catch |err| switch (err) { error.Canceled => |e| return e, error.Closed => unreachable, @@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type { /// /// Idempotent. Not threadsafe. pub fn cancel(s: *S) void { - s.outstanding = 0; s.group.cancel(s.io); } }; diff --git a/lib/std/crypto/kangarootwelve.zig b/lib/std/crypto/kangarootwelve.zig index 65d053ec5dc8b139c48f082b079284140d28b269..c072857359872bc24b120e300da58d0778243e25 100644 --- a/lib/std/crypto/kangarootwelve.zig +++ b/lib/std/crypto/kangarootwelve.zig @@ -883,6 +883,7 @@ fn ktMultiThreaded( defer allocator.free(pending_cv_buf); var pending_cv_lens: [256]usize = .{0} ** 256; + var select_outstanding: usize = 0; var select: Select = .init(io, select_buf); defer select.cancel(); var batches_spawned: usize = 0; @@ -894,6 +895,7 @@ fn ktMultiThreaded( const batch_leaves = @min(leaves_per_batch, full_leaves - batch_start_leaf); const start_offset = chunk_size + batch_start_leaf * chunk_size; + select_outstanding += 1; select.async(.batch, SelectLeafContext(Variant).process, .{SelectLeafContext(Variant){ .view = view, .batch_idx = batches_spawned, @@ -903,6 +905,7 @@ fn ktMultiThreaded( batches_spawned += 1; } + select_outstanding -= 1; const result = try select.await(); const batch = result.batch; const slot = batch.batch_idx % max_concurrent; @@ -927,7 +930,7 @@ fn ktMultiThreaded( } } - assert(select.outstanding == 0); + assert(select_outstanding == 0); } if (has_partial_leaf) { -- 2.54.0