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

This commit is contained in:
Matthew Lugg 2026-02-04 15:36:25 +01:00 committed by Alex Rønne Petersen
parent fce7878a91
commit fcdde3e4c7
No known key found for this signature in database

View file

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