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 {...@@ -337,8 +337,6 @@ const AsyncClosure = struct {
337 select_condition: ?*ResetEvent,337 select_condition: ?*ResetEvent,
338 context_alignment: std.mem.Alignment,338 context_alignment: std.mem.Alignment,
339 result_offset: usize,339 result_offset: usize,
340 /// Whether the task has a return type with nonzero bits.
341 has_result: bool,
342340
343 const done_reset_event: *ResetEvent = @ptrFromInt(@alignOf(ResetEvent));341 const done_reset_event: *ResetEvent = @ptrFromInt(@alignOf(ResetEvent));
344342
...@@ -348,12 +346,8 @@ const AsyncClosure = struct {...@@ -348,12 +346,8 @@ const AsyncClosure = struct {
348 if (@cmpxchgStrong(std.Thread.Id, &closure.cancel_tid, 0, tid, .acq_rel, .acquire)) |cancel_tid| {346 if (@cmpxchgStrong(std.Thread.Id, &closure.cancel_tid, 0, tid, .acq_rel, .acquire)) |cancel_tid| {
349 assert(cancel_tid == Closure.canceling_tid);347 assert(cancel_tid == Closure.canceling_tid);
350 // Even though we already know the task is canceled, we must still348 // Even though we already know the task is canceled, we must still
351 // run the closure in order to make the return value valid - that349 // run the closure in order to make the return value valid and in
352 // is, unless the result is zero bytes!350 // case there are side effects.
353 if (!ac.has_result) {
354 ac.reset_event.set();
355 return;
356 }
357 }351 }
358 current_closure = closure;352 current_closure = closure;
359 ac.func(ac.contextPointer(), ac.resultPointer());353 ac.func(ac.contextPointer(), ac.resultPointer());
...@@ -389,7 +383,6 @@ const AsyncClosure = struct {...@@ -389,7 +383,6 @@ const AsyncClosure = struct {
389 }383 }
390384
391 fn free(ac: *AsyncClosure, gpa: Allocator, result_len: usize) void {385 fn free(ac: *AsyncClosure, gpa: Allocator, result_len: usize) void {
392 if (!ac.has_result) assert(result_len == 0);
393 const base: [*]align(@alignOf(AsyncClosure)) u8 = @ptrCast(ac);386 const base: [*]align(@alignOf(AsyncClosure)) u8 = @ptrCast(ac);
394 gpa.free(base[0 .. ac.result_offset + result_len]);387 gpa.free(base[0 .. ac.result_offset + result_len]);
395 }388 }
...@@ -432,7 +425,6 @@ fn async(...@@ -432,7 +425,6 @@ fn async(
432 .func = start,425 .func = start,
433 .context_alignment = context_alignment,426 .context_alignment = context_alignment,
434 .result_offset = result_offset,427 .result_offset = result_offset,
435 .has_result = result.len != 0,
436 .reset_event = .unset,428 .reset_event = .unset,
437 .select_condition = null,429 .select_condition = null,
438 };430 };
...@@ -503,7 +495,6 @@ fn concurrent(...@@ -503,7 +495,6 @@ fn concurrent(
503 .func = start,495 .func = start,
504 .context_alignment = context_alignment,496 .context_alignment = context_alignment,
505 .result_offset = result_offset,497 .result_offset = result_offset,
506 .has_result = result_len != 0,
507 .reset_event = .unset,498 .reset_event = .unset,
508 .select_condition = null,499 .select_condition = null,
509 };500 };