authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-10 16:44:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-02 16:30:59-07:00
logf0499abd88be7a914935c8d8076f9ae857bbcd7d
treeb96e7052f696648a47a294e2e818532bbd4701a5
parent806214797a124b175a2318cf25f487970f4518a4

std.Io.ThreadPool: fix asyncDetached


1 files changed, 3 insertions(+), 4 deletions(-)

lib/std/Io/ThreadPool.zig+3-4
......@@ -494,13 +494,12 @@ fn async(
494494const DetachedClosure = struct {
495495 pool: *Pool,
496496 func: *const fn (context: *anyopaque) void,
497 run_node: Pool.RunQueue.Node = .{ .data = .{ .runFn = runFn } },
497 runnable: Runnable = .{ .runFn = runFn },
498498 context_alignment: std.mem.Alignment,
499499 context_len: usize,
500500
501501 fn runFn(runnable: *Pool.Runnable, _: ?usize) void {
502 const run_node: *Pool.RunQueue.Node = @fieldParentPtr("data", runnable);
503 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("run_node", run_node));
502 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("runnable", runnable));
504503 closure.func(closure.contextPointer());
505504 const gpa = closure.pool.allocator;
506505 const base: [*]align(@alignOf(DetachedClosure)) u8 = @ptrCast(closure);
......@@ -544,7 +543,7 @@ fn asyncDetached(
544543 .context_len = context.len,
545544 };
546545 @memcpy(closure.contextPointer()[0..context.len], context);
547 pool.run_queue.prepend(&closure.run_node);
546 pool.run_queue.prepend(&closure.runnable.node);
548547
549548 if (pool.threads.items.len < pool.threads.capacity) {
550549 pool.threads.addOneAssumeCapacity().* = std.Thread.spawn(.{