fix(libc): avoid coarse Windows C++ condition waits #7735
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7735"
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 MarcZX10 on 2026-10-19T04:52:57Z.
What
On Windows, route the Dinkumware
_Cnd_waitand_Cnd_timedwaitshim through native condition variables and aCRITICAL_SECTION, avoiding winpthreads'GetTickCount64timeout loop for C++ condition waits. Keep the existing standard-library path on POSIX. Timed waits round positive remaining durations up to milliseconds and recheck the absolute system-clock deadline after a timeout. The regression test measures the median of 31 one-millisecond waits with the same timer-resolution request used by AnyPS5.Related report: #1471 documents Windows
std::condition_variable::wait_untilovershooting by about 15.5 ms for a 1 ms timeout, whileSleepConditionVariableSRW(1)returned in 1.1–1.2 ms on the reported setup. This PR addresses the libc Dinkumware condition wait path only; it does not close the broader timing issue.Tested
Threads.cppandGuestLibcCndTimedWait.cpptogether with GCC 12.2 and ran the focused test successfully. This covers existing timed timeout, timed signal wake, untimed wake, and the unchanged POSIX implementation.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-19T05:04:36Z.
Some 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/libc/src/Threads.cppcore/libs/prx/libc/src/Threads.cppcore/libs/tests/GuestLibcCndTimedWait.cppcore/libs/prx/libc/src/Threads.cppcore/libs/prx/libc/src/Threads.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T05:11:32Z.
I checked the overlap bot's uncompared files manually. #1835, #5021, #6879 and #7201 each change the
tv_nsec→system_clock::durationdeadline conversion inThreads.cpp; the conversion hunk overlaps this PR, while the native Windows condition-variable wait is distinct. #6044 does not touchGuestLibcCndTimedWait.cpp.The rounded
system_clock::durationconversion is retained in this PR's Windows path. These branches are currently dirty againstmain, and #7735 has no functional dependency on them. If one rebases or merges first, this small conversion hunk can be reconciled while preserving the rounding.Imported from boykopovar/AnyPS5. Originally posted by harmsluis on 2026-10-19T18:52:40Z.
Windows run (Windows 11 build 26300, non-elevated, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
BUILD_TESTING=ON).main965dc2d78has not changedThreads.cppor this test since the PR's merge-base676d42396;git merge-treereports no conflicts.main965dc2d78, the test as it is onmain:guest_libc_cnd_timed_waitpasses 3/3. That build does not include the new 1 ms check.GuestLibcCndTimedWait.cpponmain's libc: the new check aborts (0xc0000409) 3/3. A local print of the 31 samples (not part of the PR, removed before the run below) gave medians of 15.516, 15.839 and 15.998 ms.31483262c) on965dc2d78:Threads.cppbuilds with no new warnings. The same local print gave medians of 1.503, 1.505 and 1.504 ms; one run's 31 samples ran from 1.005 to 2.529 ms. The PR's test, without that print, passes 5/5 (ctest --repeat until-fail:5).An earlier run today on
main85029a00f, same PR head, matched this: unfixed medians 15.970, 15.951 and 15.510 ms (abort 3/3), fixed medians 1.494, 1.508 and 1.496 ms, and the unmodified test passed 5/5.Not covered: the full build, and any title run.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:27:07Z.
Thanks for the controlled Windows comparison. The baseline test passes while the new timing assertion reproduces the coarse wait failure 3/3; with the PR it passes 5/5, and the measured medians drop from roughly 15.5–16.0 ms to roughly 1.5 ms. I’ll cite this as focused Windows validation and keep the full-build and title-run limitations explicit.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T01:16:09Z.
Checked the Windows
_Cnd_wait/_Cnd_timedwaitpaths (nativeCONDITION_VARIABLE+CRITICAL_SECTION, ms round-up, deadline recheck onERROR_TIMEOUT, signal/broadcast) and the POSIX path (unchanged), and that the new 31-sample 1 ms median test and the untimed-wait case pin the behaviour; the full Linux and Windows Build covers the Windows runtime. Merged.