authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-04 15:36:25+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-04 20:44:37+01:00
logfcdde3e4c796fcaf160b6161040df8d458523e95
tree0f3e6cb885d8fd1c6d91f8ef9dc2c4dcd73edc83
parentfce7878a9149caa80433e6d650e0bd7f60d345fd
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Io.Threaded: gracefully handle race leading to ESRCH in unpark()


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

lib/std/Io/Threaded.zig+7-3
......@@ -17548,8 +17548,8 @@ fn unpark(tids: []const UnparkTid, addr_hint: ?*const anyopaque) void {
1754817548 switch (posix.errno(std.c._lwp_unpark_all(@ptrCast(tids.ptr), tids.len, addr_hint))) {
1754917549 .SUCCESS => return,
1755017550 // For errors, fall through to a loop over `tids`, though this is only expected to
17551 // be possible for ENOMEM (and even that is questionable).
17552 .SRCH => recoverableOsBugDetected(),
17551 // be possible for ENOMEM (even that is questionable) and ESRCH (see comment below).
17552 .SRCH => {},
1755317553 .FAULT => recoverableOsBugDetected(),
1755417554 .INVAL => recoverableOsBugDetected(),
1755517555 .NOMEM => {},
......@@ -17558,7 +17558,11 @@ fn unpark(tids: []const UnparkTid, addr_hint: ?*const anyopaque) void {
1755817558 for (tids) |tid| {
1755917559 switch (posix.errno(std.c._lwp_unpark(@bitCast(tid), addr_hint))) {
1756017560 .SUCCESS => {},
17561 .SRCH => recoverableOsBugDetected(),
17561 .SRCH => {
17562 // This can happen in a rare race: the thread might have been spuriously
17563 // unparked, so already observed the changing status, and from there have
17564 // exited. That's okay, because the thread has woken up like we wanted.
17565 },
1756217566 else => recoverableOsBugDetected(),
1756317567 }
1756417568 }