authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-24 06:23:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
log85e159e652afe976a6f720e041e88b196f062a9f
tree49e381661cf805b82244a9651c415e7a96de2482
parented7067a690444a362d289fe5b0a75eefa0de4f08

std.Io.Threaded: closures must always be run even when canceled


1 files changed, 2 insertions(+), 11 deletions(-)

lib/std/Io/Threaded.zig+2-11
......@@ -337,8 +337,6 @@ const AsyncClosure = struct {
337337 select_condition: ?*ResetEvent,
338338 context_alignment: std.mem.Alignment,
339339 result_offset: usize,
340 /// Whether the task has a return type with nonzero bits.
341 has_result: bool,
342340
343341 const done_reset_event: *ResetEvent = @ptrFromInt(@alignOf(ResetEvent));
344342
......@@ -348,12 +346,8 @@ const AsyncClosure = struct {
348346 if (@cmpxchgStrong(std.Thread.Id, &closure.cancel_tid, 0, tid, .acq_rel, .acquire)) |cancel_tid| {
349347 assert(cancel_tid == Closure.canceling_tid);
350348 // Even though we already know the task is canceled, we must still
351 // run the closure in order to make the return value valid - that
352 // is, unless the result is zero bytes!
353 if (!ac.has_result) {
354 ac.reset_event.set();
355 return;
356 }
349 // run the closure in order to make the return value valid and in
350 // case there are side effects.
357351 }
358352 current_closure = closure;
359353 ac.func(ac.contextPointer(), ac.resultPointer());
......@@ -389,7 +383,6 @@ const AsyncClosure = struct {
389383 }
390384
391385 fn free(ac: *AsyncClosure, gpa: Allocator, result_len: usize) void {
392 if (!ac.has_result) assert(result_len == 0);
393386 const base: [*]align(@alignOf(AsyncClosure)) u8 = @ptrCast(ac);
394387 gpa.free(base[0 .. ac.result_offset + result_len]);
395388 }
......@@ -432,7 +425,6 @@ fn async(
432425 .func = start,
433426 .context_alignment = context_alignment,
434427 .result_offset = result_offset,
435 .has_result = result.len != 0,
436428 .reset_event = .unset,
437429 .select_condition = null,
438430 };
......@@ -503,7 +495,6 @@ fn concurrent(
503495 .func = start,
504496 .context_alignment = context_alignment,
505497 .result_offset = result_offset,
506 .has_result = result_len != 0,
507498 .reset_event = .unset,
508499 .select_condition = null,
509500 };