Repository navigation
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, boykopovar#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 boykopovar#28045, which does not touch threads. With boykopovar#28045's libraries it fails as often as onmain(20 of 400). Run alone it passes, as in the earlier reports on boykopovar#21742 and boykopovar#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