fix(libc): run std::_Execute_once callbacks under a per-flag lock #5027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5027"
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 0xRickx on 2026-10-13T08:52:41Z.
What
libc's guest export of Dinkumware's
std::_Execute_once, whichstd::call_onceuses, held one process-widestd::recursive_mutexwhile the callback ran. Everycall_oncein the process was serialized behind it, so a callback that waited for another thread runningcall_onceon a different flag deadlocked, or its timed wait expired.[thread.once.callonce] only orders executions on the same
once_flag, and MSVC's STL implements Dinkumware's_Execute_onceper flag withInitOnceExecuteOnce, whose callback type is this one. Callers now wait only while their own flag is being initialized. The callback runs with no lock held, and a guard publishes the flag and wakes the waiters on every exit. A callback that returns 0 or throws leaves the flag at 0, so the next caller runs it, as before; the flag word still only holds 0 or 1. A recursive call on the flag the calling thread is initializing now throwsstd::runtime_error: the recursive mutex let the callback run a second time, where C++ deadlocks.A callback that ends its thread (
scePthreadExit) skips the guard, so later callers of that one flag wait forever. Before this change everycall_oncein the process did.Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release:
guest_execute_oncegains three cases:The 16-thread run-once check is unchanged.
guest_execute_once,guest_std_execute_onceandguest_oncepass with--repeat until-fail:5onmain4bb2c7f3.Full ctest on
mainad653c9b: 1044/1045 passed (8 skipped on this machine). The one failure,patched_libraries, ismain'slibkernel_sys.prxload failure on Windows, fixed by #5025.tools/check_conventions.py --base upstream/mainpasses.Rebased onto
mainffa2a6ecwithout conflicts (head684dd88f), then tested again onmainc496fd53:guest_execute_once,guest_std_execute_onceandguest_oncepass. Full ctest: 1088/1088 passed (8 skipped on this machine).guest_execute_once,guest_std_execute_onceandguest_oncepass.guest_math,agc_driver_depth_compare_copyandguest_socket_read_writefail the same way onmainb8683834without any of them in this setup.No title was run.
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 oneandonlydean on 2026-10-14T02:34:20Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed