Repository navigation
test(libkernel): wait until a released thread leaves the registry - #28064
oneandonlydean merged 1 commit into
Conversation
guest_pthread_released_handle waited until scePthreadGetprio answered ESRCH and then expected every call on the handle to answer ESRCH. scePthreadGetprio answers ESRCH as soon as the thread has finished, but the handle stays registered until its last reference is released. In that window pthread_getname_np still returns the name and scePthreadJoin returns EINVAL for the detached thread, so the test aborted when the exiting thread was slow to drop its reference. Wait until pthread_getname_np answers ESRCH, which it does only once the handle has left the registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Other Merge Risk:
|
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d165e69efc:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_pthread_released_handle_testsbuilt cleanly. - CTest (
guest_pthread_released_handle):1/1 Test #6515: guest_pthread_released_handle .... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified core/libs/tests/GuestPthreadReleasedHandle.cpp:WaitUntilReleased signature and usage of pthread_getname_np_nid_postfix(thread, name) with buffer char name[64].
- Verified return error code GUEST_ESRCH matching the expected error returned when a thread handle has been fully released and removed from the thread registry.
- Verified loop termination logic and deadline assertion (Require(steady_clock::now() < deadline)) with std::this_thread::yield() to prevent deadlocks or infinite spinning.
- Checked AGENTS.md rules compliance (no comments added, no hardcoded title IDs, clean conventions, no extra files).
- Verified memory safety and buffer bounds: char name[64] is stack-allocated and sufficient for pthread_getname_np name length.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
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
- Reviewed head
d165e69efc98a753c05592074eb48910153a9a9e. - Read the prepared description, commit summary, manifest, diff, changed test file, and the
pthread_getname_np_nid_postfiximplementation. - Used
repo_read.pysearch and cat operations to inspect references and relevant implementation lines. No tests or builds were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed test | passed | Change matches stated goal |
| Target implementation | passed | Returns ESRCH when unregistered |
| Tests or build | not run | No local execution |
Findings
Blocking
None.
Non-blocking
None.
Not verified
- Runtime behavior and test results reported in the PR description were not independently verified.
- No files were listed as excluded in the available prepared bundle; the changed file was read in full.
To get this to a good state
Nothing is required.
|
Linux check of the exact head
AI-assisted: yes |
ligmaSec
left a comment
There was a problem hiding this comment.
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.
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