Repository navigation
fix(libkernel): release every level of a recursive mutex during a cond wait - #1480
Merged
oneandonlydean merged 1 commit intoOct 9, 2026
Merged
Conversation
…d wait A condition wait on a recursive mutex locked more than once unlocked the native mutex only once, so the thread that should signal blocked forever on it. Unlock the remaining levels before the wait and lock them again after it, as FreeBSD libthr does in _mutex_cv_unlock and _mutex_cv_lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
9 tasks done
Collaborator
|
Could you rebase onto current main? The full build checks out this branch with main's workflow, and it stops at |
Contributor
|
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
No title was run. 🤖 Addressed by Claude Code |
9 tasks done
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
A condition wait on a recursive mutex that the waiter has locked more than once deadlocks.
waitUntilinPthread/src/Cond.cppcleared_countand_owner, but the condition variable unlocks the nativestd::recursive_timed_mutexonly once. EveryscePthreadMutexLockon a recursive mutex locks the native mutex again, so after N locks the waiter still holds N-1 levels during the wait. The thread that should take the mutex and signal blocks inscePthreadMutexLock, and the waiter never wakes (an untimed wait hangs; a timed wait times out forever).FreeBSD libthr, which the PS5 libkernel is based on, releases the mutex completely for the wait and restores the recursion count afterwards:
_mutex_cv_unlock/_mutex_cv_detachsavem_count, set it to 0 and unlock, and_mutex_cv_lock/_mutex_cv_attachput it back (thr_mutex.c, thr_cond.ccond_wait_kernel/cond_wait_user).The fix unlocks the remaining N-1 native levels before the wait and locks them again after it. This covers
scePthreadCondWait,scePthreadCondTimedwait,pthread_cond_waitandpthread_cond_timedwait, which all go throughwaitUntil. The FreeBSD behaviour is recorded in TechnicalDebt as unverified on hardware.guest_cond_recursive_mutexlocks a recursive mutex twice and waits with each of the four functions while another thread locks the mutex and signals. After the wake the waiter unlocks twice and a third unlock returnsSCE_KERNEL_ERROR_EPERM.This PR was investigated and written by Claude Code (AI), and posted by me after review.
Tested
Arch Linux, GCC, Release,
-DBUILD_TESTING=ON,APS5_WRITE_WATCH_IMPORTS=watch(Intel UHD 630 + GTX 1050 Ti).guest_cond_recursive_mutex: passes; with only theCond.cppchange reverted it fails (ctest timeout, the signalling thread never gets the mutex).ctest -j4: 424/424 passed, 0 skipped, 0 failed (mainbc1fbe8: 423/423, 0 skipped; the new test is the only difference).VK_LAYER_KHRONOS_validation: 424/424 passed, 0 skipped; 27Validation Errormessages with the same VUIDs and counts asmain(52VUID-vkDestroyDevice-device-05137, 2VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605).tools/check_conventions.py: passes.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
https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8