fix(libkernel): cancel Windows joins during native thread cleanup #4901
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4901"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-13T03:04:51Z.
What
On Windows,
scePthreadJoincan reach native thread cleanup after the guest result is ready (_finished). The finalWaitForSingleObjectignored guest cancellation: a joiner canceled during a gated FLS destructor waited for the destructor to finish, returned success and overwrote its output instead of exiting withPTHREAD_CANCELED.Wait on the joinee's native handle and the joining thread's existing
wakeEvent, created lazily and signaled undercancelLock. Keep cancellation checks outside the join/cancel mutexes and before storing the result or releasing the joinee, so a canceled join leaves its output untouched and its target joinable. Disabled cancellation and cleanup handlers already exiting use the ordinary native wait.Cancelholds an existing ownership reference before publishing the request and releases it after unlocking, including exceptions. This prevents an adopted/detached target from deleting its cancellation mutex while the signaling caller still uses it. FLS cleanup closes the event on an adopted host thread's ordinary return. Existing retention of that adopted thread object and duplicated native handle remains recorded in libkernel debt. The thread-state type is internal so its destructor/template helpers do not become NIDs.Authors agreed to land this correction first: #4481 / #4533 and #4563. Their lifecycle adaptations must preserve the cancellation/retry regression. Native FLS cleanup can block after
_finished; making that wait non-cancellable would reintroduce the demonstrated failure. A revocable reap is an untested proposal, and combined compatibility is not claimed here.Tested
Windows, MinGW-w64 GCC 15.2, Release, BUILD_TESTING=ON, rebased on main
068ab2aba.The rebase resolves adjacent edits in libkernel debt by preserving main's updated cpuset text and this PR's cancellation entry. The cancellation code and recovery fixture are unchanged. A clean merge with main
27477e5f4was verified before publishing._finishedand uses Windows Wait Chain Traversal to establish that the joiner reached the native wait. The original join failed withcanceledBeforeRelease=0 returned=1 outputUntouched=0; the fix exits before releasing the target, preserves the output and permits a later join.git diff --checkpass. Independent source review found no remaining issue with the event/reference ownership.Not tested: Linux/macOS execution, a PS5 console, a game, or this change combined with the pending lifecycle PRs. FreeBSD libthr is the existing cancellation reference, linked in libkernel debt. No title unblock or performance improvement is claimed.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:42:56Z.
Windows test: head
d6f98edacmerged onto currentmainea2bbefb2(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_pthread_cancel_recovery: guest_pthread_cancel_recovery passed, guest_pthread_cancel_recovery_coarse passed (2 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T15:55:23Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/Pthread/src/Thread.cppL792-793Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:36:25Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed