From c199124a84f3c4b8d1eabb10620ae5be7d0275f9 Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Fri, 7 Nov 2025 13:33:45 +0100 Subject: [PATCH] fix logic bug in groupAsync --- lib/std/Io/Threaded.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 4f4b547743..24ce92dfb1 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -695,10 +695,6 @@ fn groupAsync( t.mutex.lock(); - // Append to the group linked list inside the mutex to make `Io.Group.async` thread-safe. - gc.node = .{ .next = @ptrCast(@alignCast(group.token)) }; - group.token = &gc.node; - if (t.available_thread_count == 0) { if (t.cpu_count != 0 and t.threads.items.len >= t.cpu_count) { t.mutex.unlock(); @@ -727,6 +723,10 @@ fn groupAsync( t.available_thread_count -= 1; } + // Append to the group linked list inside the mutex to make `Io.Group.async` thread-safe. + gc.node = .{ .next = @ptrCast(@alignCast(group.token)) }; + group.token = &gc.node; + t.run_queue.prepend(&gc.closure.node); // This needs to be done before unlocking the mutex to avoid a race with