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 {...@@ -17548,8 +17548,8 @@ fn unpark(tids: []const UnparkTid, addr_hint: ?*const anyopaque) void {
17548 switch (posix.errno(std.c._lwp_unpark_all(@ptrCast(tids.ptr), tids.len, addr_hint))) {17548 switch (posix.errno(std.c._lwp_unpark_all(@ptrCast(tids.ptr), tids.len, addr_hint))) {
17549 .SUCCESS => return,17549 .SUCCESS => return,
17550 // For errors, fall through to a loop over `tids`, though this is only expected to17550 // 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).17551 // be possible for ENOMEM (even that is questionable) and ESRCH (see comment below).
17552 .SRCH => recoverableOsBugDetected(),17552 .SRCH => {},
17553 .FAULT => recoverableOsBugDetected(),17553 .FAULT => recoverableOsBugDetected(),
17554 .INVAL => recoverableOsBugDetected(),17554 .INVAL => recoverableOsBugDetected(),
17555 .NOMEM => {},17555 .NOMEM => {},
...@@ -17558,7 +17558,11 @@ fn unpark(tids: []const UnparkTid, addr_hint: ?*const anyopaque) void {...@@ -17558,7 +17558,11 @@ fn unpark(tids: []const UnparkTid, addr_hint: ?*const anyopaque) void {
17558 for (tids) |tid| {17558 for (tids) |tid| {
17559 switch (posix.errno(std.c._lwp_unpark(@bitCast(tid), addr_hint))) {17559 switch (posix.errno(std.c._lwp_unpark(@bitCast(tid), addr_hint))) {
17560 .SUCCESS => {},17560 .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 },
17562 else => recoverableOsBugDetected(),17566 else => recoverableOsBugDetected(),
17563 }17567 }
17564 }17568 }