authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-03-31 17:06:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-20 10:38:39-07:00
logfa937d686d1ba86d6dba47f92353c139bd2145fc
treed8d8dfa9457d5124445e724c13bcd26901c3df0c
parent74969d1c40fdc31c8d8df6df2619304aaa1a533b

EventLoop: remove broken mechanism for making deinit block on detached


1 files changed, 1 insertions(+), 16 deletions(-)

lib/std/Io/EventLoop.zig+1-16
......@@ -27,7 +27,6 @@ const Thread = struct {
2727 current_context: *Context,
2828 ready_queue: ?*Fiber,
2929 free_queue: ?*Fiber,
30 detached_queue: ?*Fiber,
3130 io_uring: IoUring,
3231 idle_search_index: u32,
3332 steal_ready_search_index: u32,
......@@ -209,7 +208,6 @@ pub fn init(el: *EventLoop, gpa: Allocator) !void {
209208 .current_context = &main_fiber.context,
210209 .ready_queue = null,
211210 .free_queue = null,
212 .detached_queue = null,
213211 .io_uring = try IoUring.init(io_uring_entries, 0),
214212 .idle_search_index = 1,
215213 .steal_ready_search_index = 1,
......@@ -220,16 +218,7 @@ pub fn init(el: *EventLoop, gpa: Allocator) !void {
220218}
221219
222220pub fn deinit(el: *EventLoop) void {
223 // Wait for detached fibers.
224221 const active_threads = @atomicLoad(u32, &el.threads.active, .acquire);
225 for (el.threads.allocated[0..active_threads]) |*thread| {
226 while (thread.detached_queue) |detached_fiber| {
227 if (@atomicLoad(?*Fiber, &detached_fiber.awaiter, .acquire) != Fiber.finished)
228 el.yield(null, .{ .register_awaiter = &detached_fiber.awaiter });
229 detached_fiber.recycle();
230 }
231 }
232
233222 for (el.threads.allocated[0..active_threads]) |*thread| {
234223 const ready_fiber = @atomicLoad(?*Fiber, &thread.ready_queue, .monotonic);
235224 assert(ready_fiber == null or ready_fiber == Fiber.finished); // pending async
......@@ -347,7 +336,6 @@ fn schedule(el: *EventLoop, thread: *Thread, ready_queue: Fiber.Queue) void {
347336 .current_context = &new_thread.idle_context,
348337 .ready_queue = ready_queue.head,
349338 .free_queue = null,
350 .detached_queue = null,
351339 .io_uring = IoUring.init(io_uring_entries, 0) catch |err| {
352340 @atomicStore(u32, &el.threads.reserved, new_thread_index, .release);
353341 // no more access to `thread` after giving up reservation
......@@ -673,8 +661,6 @@ const DetachedClosure = struct {
673661 message.handle(closure.event_loop);
674662 std.log.debug("{*} performing async detached", .{closure.fiber});
675663 closure.start(closure.contextPointer());
676 const current_thread: *Thread = .current();
677 current_thread.detached_queue = closure.fiber.queue_next;
678664 const awaiter = @atomicRmw(?*Fiber, &closure.fiber.awaiter, .Xchg, Fiber.finished, .acq_rel);
679665 if (awaiter) |a| {
680666 closure.event_loop.yield(a, .nothing);
......@@ -766,11 +752,10 @@ fn go(
766752 else => |arch| @compileError("unimplemented architecture: " ++ @tagName(arch)),
767753 },
768754 .awaiter = null,
769 .queue_next = current_thread.detached_queue,
755 .queue_next = null,
770756 .cancel_thread = null,
771757 .awaiting_completions = .initEmpty(),
772758 };
773 current_thread.detached_queue = fiber;
774759 closure.* = .{
775760 .event_loop = event_loop,
776761 .fiber = fiber,