Commit 69f9395b38

Loris Cro <kappaloris@gmail.com>
2025-11-07 13:33:45
fix logic bug in groupAsync
1 parent ff883dd
Changed files (1)
lib
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