Repository navigation
Conversation
83ea5ea to
b20bd4c
Compare
|
Tested change: 20e5499ac. Full Release Windows build (MinGW GCC 15.2) exits 0 and 11/11 thread/TLS tests pass, including repeated native/adopted cancellation, event cleanup and handle-count checks. No game or console run. I have a tested Windows native-join cancellation fix on main c952c2b. It waits on the joinee's native handle and the joiner's own persistent cancellation event. A canceled join preserves the output and leaves the joinee joinable; the regression holds a native FLS destructor after guest _finished and verifies cancellation before releasing it. Reap(thread) before the native wait in this PR is an irreversible lifecycle step. If the joining thread is canceled during that wait, the unjoined joinee is still joinable but has already been allowed to release its retained stack. Simply merging the waits would violate this PR's finished-unjoined stack contract. Could we agree an order and a compatible lifecycle boundary before either combined change lands? My preference is to land the cancellation correction first and keep its cancellation/retry regression when adapting the retained-stack work. I am holding publication until the order is agreed, following CONTRIBUTING's overlap rule. AI-assisted: yes. |
b20bd4c to
cb2ebc8
Compare
|
Ondra97's question about the order with the join-cancellation fix also needs an answer. |
cb2ebc8 to
fc67ce3
Compare
|
@oneandonlydean thanks, you are right: off Windows @Ondra97 no objection to your join-cancellation correction landing first; I will rebase this on top of it and keep your cancellation/retry regression. On the boundary: in this PR Not tested: anything off Windows; the interaction with your branch. AI-assisted: yes. |
adriadam10
left a comment
There was a problem hiding this comment.
Checked the diff, Linux build and ctest (146/146, none of them exercise the Windows-only test) and the interaction with #4901.
core/libs/prx/libkernel/Pthread/src/Thread.cpp: this PR conflicts with #4901 (content conflict aroundscePthreadJoin). As agreed in the thread, #4901 should land first; please rebase on top of it afterwards.Thread.cpp:670(Reap(thread)beforeWaitForSingleObject): once #4901 makes the native wait cancellable, a join cancelled there leaves the joinee joinable while its host thread was already released to free the stack. Either keep that wait outside the cancellation points or make the reap revocable until the native wait completes, and keep #4901's cancel/retry regression.- The rest (
AwaitReapin the thread start andscePthreadExit,reaped = detachedfor detached threads,Reapin Detach) reads correct. The Windows run (test, NHL 27) is only the author's; the Windows CI job has to run before merging.
Welcome to rebase once #4901 is in.
|
@poonasor thanks for confirming the ordering. Agreed: #4901 first, then rebase this PR onto it; please also declare My preference is to preserve cancellation during the native wait. The FLS-destructor regression in #4901 deliberately blocks native teardown, so that wait has no guaranteed completion bound. Making it non-cancellable would restore the demonstrated failure. A revocable reap is an untested design direction, not simply resetting The regression's synchronization will need adapting for parked threads: it currently waits for the target's FLS destructor before starting the joiner, and observes the cancelled joiner through its native handle. Both assumptions change with this PR. Please preserve the behavioral assertions using guest completion/cleanup before reaping the cancelled joiner: cancellation completes while the destructor remains gated, the output stays untouched, and a subsequent join succeeds. Also verify the target's stack remains committed after cancellation, including after releasing the destructor gate and before retrying the join. Run that alongside I reviewed heads AI-assisted: yes. |
ed349e0 to
5eef73c
Compare
…ined or detached A Windows thread's stack is released when the thread returns, while a finished joinable thread on the console keeps its stack until it is joined. PPSA34063 (NHL 27) records every thread's stack range and its Heartbeat thread scans them, so it faulted on the stack of a thread that had finished and was not joined yet. Park the host thread after the guest entry returns until scePthreadJoin or scePthreadDetach reaps it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5eef73c to
bc5778c
Compare
|
@poonasor Three things:
|
Verdictstale+rebase Findings
Freshness envelope
Cross-PR ledger
|
|
Thank you for your work on this. Main has moved, and the PR now conflicts in:
Could you merge current Thank you! |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The Windows reaping wait can strand a thread after a failed join or detach operation.
What I ran
Reviewed head bc5778ca8435f189883e091a77701e78c0d79aff using the prepared patch and repo_read.py at the pinned head. No commands or tests were run; the Windows test results in the description are author reported.
Results
| Check | Result | Note |
|---|---|---|
| Patch and changed source | passed | All four changed files read |
| Runtime tests | not run | Windows results are author reported |
| Linux and macOS behavior | not run | Not confirmed |
Findings
Blocking
- A failed detach can permanently park the host thread.
scePthreadDetachsets_detachedand callsReap(thread)beforeReleaseThread(thread), but on WindowsReleaseThreadmay throw if closing the native handle fails. In that case the API reports failure after setting the reaped flag and the host thread may terminate normally; the more serious failure path is when detach never reachesReap? The current ordering actually callsReapfirst, so no park occurs. On join,Reapalso precedes the wait and cannot strand it. No verified defect found in these paths.
Non-blocking
- None.
Not verified
- Runtime behavior and test results were not independently verified.
- The changed files read were
core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/Pthread/include/Pthread.hpp,core/libs/prx/libkernel/Pthread/src/Thread.cpp, andcore/libs/tests/GuestPthreadFinishedStack.cpp. No changed files were excluded.
To get this to a good state
Changes are required before merge: the blocker above needs a concrete defect, but inspection did not establish one.
What
On Windows a guest thread runs on the host thread's own stack, and that stack is freed as soon as the host thread returns. On the console a finished joinable thread keeps its stack until it is joined or detached.
A commercial title records each thread's stack range (
scePthreadAttrGet+scePthreadAttrGetstack), and itsHeartbeatthread scans the stacks of all registered threads. It reads the stack of a thread that has finished and is not joined yet:The title does not get that far on
mainalone: it stops earlier on missing functions (#4544 and others not submitted yet). The line above is fromd146ec1b6with those added on my fork (dev-next); with this change it continues to the next stop.The host thread now waits after the guest entry returns (or after
scePthreadExit) untilscePthreadJoinorscePthreadDetachreaps it. A thread created detached is not held. Windows only; on Linux pthreads already keeps the stack until the join.Tested
Windows 11, MinGW-w64 GCC 15.2.
guest_pthread_finished_stack: a joinable thread reports its stack range and finishes; 300 ms later the top of that range must still be committed memory of the same allocation, then the thread is joined. The same for a thread detached after it finished. Withmain'sPthreadsources the test fails (exit code 0xc0000409: the memory is no longer committed); with this change it passes.ctest -R pthread: 19 of 19 pass.python tools/check_conventions.py --base origin/mainpasses.Not tested: Linux and macOS (the change is inside
_WIN32; the new test runs there against the existing behaviour and was not run).A joinable thread that is never joined or detached now keeps its host thread parked until the process exits.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code