fix(libkernel): preserve condition signals across cancellation #6091
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6091"
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 Ondra97 on 2026-10-14T21:42:06Z.
What
When a condition signal selects a waiter that is canceled while reacquiring its mutex, that waiter exits without returning the signal. A second waiter can remain blocked indefinitely. On main, the deterministic two-waiter reproduction sends one signal, cancels the selected waiter while the signaler still holds the mutex, and the survivor times out.
Condition wait completion now restores mutex ownership and recursive depth, makes one cancellation decision, and forwards a notification before cancellation cleanup. The host condition state is held separately across the wait: a caller can destroy and free its condition after notification while the awakened waiter is still reacquiring the mutex. The retained owner is explicitly released before guest thread exit, which does not unwind C++ stack objects.
The behavior follows the POSIX condition wait and cancellation contract. Cancellation may produce a spurious wake, which the contract permits. Console cancellation ordering and signal replacement remain unmeasured and are recorded in technical debt.
Tested
Windows 11 Pro build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Release,
BUILD_TESTING=ON, fullbuild-runtimeconfiguration.fa539dd9, unchanged production: existing cancellation recovery tests pass. The public-API scratch reproduction leaves the survivor atETIMEDOUT; the new registered recovery case fails in 2.22 s after the selected waiter exits canceled.f59d91ffc. All 19 targeted synchronization/runtime and patched-library tests passed without skips; the final run completed in 0.58 s. Conventions, whitespace, test registration, the repository overlap checker and two independent source/test reviews passed.errnoaround sleep; #5473 inherits identical relevant blobs; #6044 only relocates unchanged tests; #4481/#4563 concern join and stack lifetime.PthreadCondPrivateis unchanged in all 23 shared header PRs. No other open PR implements this fix.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T07:33:04Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/Pthread/src/Cond.cppL43-48, L76-77, L118, L168, L173, L179Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Pthread/include/Pthread.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestPthreadCancelRecovery.cppcore/libs/prx/libkernel/Pthread/include/Pthread.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/include/Pthread.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/include/Pthread.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:45:34Z.
Checked the cancellation path in
Cond.cpp(the condition is held byshared_ptracross the wait, the notification is forwarded beforescePthreadExit, mutex and recursive depth restored first) and the new recovery cases;guest_pthread_cancel_recoveryand the coarse variant pass on Linux with the PR merged onto current main. Merging once the Windows build is green.