test(libkernel): wait until a released thread leaves the registry #28064
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28064"
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 Plyxen on 2026-11-28T10:24:37Z.
What
guest_pthread_released_handleaborts in about 5% of runs when the machine is busy. ItsWaitUntilReleasedloop takes ESRCH fromscePthreadGetprioto mean that the handle has been released, and then requires ESRCH from every other call on it. The handle is not released at that point yet:scePthreadGetpriousesLockLiveGuestThread, which answers ESRCH as soon asfinishThreadhas set_finished;ReleaseThreadand~PthreadPrivateerases it;pthread_getname_np,scePthreadJoinandscePthreadDetachuseLockRegisteredGuestThread. In between,pthread_getname_npstill returns the name, andscePthreadJoinreturns EINVAL because the thread is detached.The exiting thread drops its reference after
finishThreadreturns, so the window is short. It is long enough when that thread is preempted.WaitUntilReleasednow waits untilpthread_getname_npanswers ESRCH, which for a detached thread happens only once the handle has left the registry. The checks after it are unchanged.I did not change the exports. A finished detached thread that is still registered is a state the console has too: FreeBSD's libthr keeps a dead thread until it is collected, and its
pthread_joinreturns EINVAL for a detached thread in that state, as ours does. Itspthread_getname_npanswers ESRCH for a dead thread, while ours returns the name until the handle is released. Using a detached thread's handle after it exits is undefined, and I have no console measurement of that window, so this PR leaves the behaviour as it is.Tested
Tested on
mainc6331cc61b. The branch is onmain9f02806678, where the test file is the same. The only libkernel change between them, #21969, moves thread objects to the guest heap and doesn't change when a thread leaves the registry. Copies ofguest_pthread_released_handle_testsran at once, in a loop:mainAPS5_NO_PROCMAP_QUERY=1On
main, a copy of the test that prints the line of the failing check showed 20 failures at thepthread_getname_npcheck and 1 at thescePthreadJoincheck. I first saw it fail in a fullctest -j 8run of #28045, which does not touch threads. With #28045's libraries it fails as often as onmain(20 of 400). Run alone it passes, as in the earlier reports on #21742 and #23953.Test only, so there is no debt change.
python3 tools/pr_overlap.py --names WaitUntilReleased GuestPthreadReleasedHandlereports no open PR changing them.python3 tools/pr_overlap.py --branch test/libkernel-released-handle-wait-for-releasereports no overlap with open pull requests.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)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T10:28:19Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d165e69efc:tools/check_conventions.pypassed.guest_pthread_released_handle_testsbuilt cleanly.guest_pthread_released_handle):Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T10:46:51Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this test change; the retry condition now waits for the registry lookup to report ESRCH before checking the released handle.
What I ran
d165e69efc98a753c05592074eb48910153a9a9e.pthread_getname_np_nid_postfiximplementation.repo_read.pysearch and cat operations to inspect references and relevant implementation lines. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T07:04:08Z.
Review: COMMENTED
Built and ran the released-pthread-handle fixture on Linux. It passed, including the wait for the released thread to leave the registry before asserting on the handle.
AI-assisted: yes.