Skip to content

feat(libc): bridge libc++ thread lifecycle - #24318

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
DonRyuzaki:codex/libcxx-thread-lifecycle-20261120
Nov 21, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
DonRyuzaki:codex/libcxx-thread-lifecycle-20261120

Conversation

@DonRyuzaki

Copy link
Copy Markdown
Contributor

What

Provide the std::__1::thread join, detach, and destructor imports listed for Azahar in RetroArch PPSA99169 in #5927's grouped inventory. LLVM libc++ 17 forwards join and detach to pthread, clears the handle only on success, and terminates on destruction of a joinable thread. This PR uses the existing guest pthread registrations and a pointer-sized thread handle. The debt fragment records the unverified console provider, exact class layout, exception ABI, termination behavior, and title behavior.

Tested

Windows 11, WinLibs GCC 15.2, Release: guest_libcxx_thread_tests built and passed its focused CTest case 20 consecutive times on the final head. It covers empty join and detach reporting EINVAL, failed self-join preserving the handle, successful join waiting and clearing the handle, successful detach clearing the handle while the worker completes, and destruction of an empty handle. The PE export table contains all three exact names. Conventions, debt fold, and diff checks passed.

Linux WSL2, GCC 13.3, Release: guest_libcxx_thread_tests built and passed its focused CTest case ten consecutive times on the final head. No Azahar or console run. Exact-name screening found none of the three imports on current main or 2,075 open PRs. The final full overlap scan fetched 2,090 open PR heads and merge-tested 31 shared-file candidates. It found no same-export owner or merge conflict. Eight older PRs could not be compared automatically because they already conflict with main (#1835, #9447, #12682, #12688, #12700, #12965, #18112, #18135); I inspected their changed-file lists and relevant Threads.cpp or Api.hpp patches. They change other functions or header regions and do not define these three libc++ thread exports. The branch is based on main 0a025bd and merge-tests cleanly with open #24261.

Checklist

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The implementation follows the stated lifecycle behavior in the code inspected, but the console provider and guest ABI assumptions remain unverified, so a formal approval is not justified.

What I ran

Reviewed head f9c2a40f36d64817f66b182407524a26aaa3aae1 using the prepared diff and repository reader. No commands or tests were run. The author reports Windows and WSL2 focused tests passed; I did not verify those runs.

Results

Check Result Note
Diff and source review passed All five changed files read
Focused tests not run Results supplied by author
Console behavior not run No Azahar or console run reported

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libc/src/Threads.cpp:674 assumes the guest std::__1::thread object is represented by one pointer-sized Pthread handle and relies on the guest exception ABI for join and detach errors. The debt note records these assumptions; the exact firmware layout and console provider have not been measured. Confirm them against the target runtime before relying on these exports in a title.

Not verified

No tests, build, export-table check, Azahar run, or console behavior were verified in this review. The author reports the focused tests and export check passed. Read all changed files listed in the manifest: core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/Threads.cpp, core/libs/prx/libc/tests/cmake/guest_libcxx_thread.cmake, core/libs/tests/GuestLibcxxThread.cpp, and docs/dev/debt/changes/feat-libc-libcxx-thread-lifecycle.md. The file listing marks all five as included; no changed files were excluded.

To get this to a good state

Nothing is required. Optional: verify the guest layout, exception behavior, and provider on the target runtime before depending on these imports in a title.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against f9c2a40f36:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libcxx_thread_tests built cleanly.
  • CTest (guest_libcxx_thread):
    1/1 Test #1490: guest_libcxx_thread ..............   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/Threads.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified CheckedLibcxxThread in core/libs/prx/libc/src/Threads.cpp validates alignment, writability via GuestWritable_nid_no_patch, and copies the thread handle safely via GuestCopyIn_nid_no_patch
    • Verified _ZNSt3__16thread4joinEv_nid_postfix and _ZNSt3__16thread6detachEv_nid_postfix correctly clear the thread handle only upon successful completion and raise std::system_error(EINVAL) when handle is null
    • Verified _ZNSt3__16threadD1Ev_nid_postfix terminates via std::terminate if and only if the thread is joinable (non-null handle) conforming to libc++ specification
    • Verified atomic loads of registeredPthreadJoin and registeredPthreadDetach use acquire semantics and handle uninitialized libkernel registration by throwing std::runtime_error
    • Verified docs/dev/debt/changes/feat-libc-libcxx-thread-lifecycle.md adheres to debt fragment conventions and documents known gaps and assumptions
    • Verified guest_libcxx_thread_tests covers empty join/detach, failed self-join handle retention, join completion, detach completion, and destructor semantics

Looks Good To Me

@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line libc build docs labels Nov 20, 2026
@github-actions

Copy link
Copy Markdown

Progress report (0a025bd → f9c2a40)

📈 System libraries: 44.56% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libc _ZNSt3__16thread4joinEv_nid_postfix
libc _ZNSt3__16thread6detachEv_nid_postfix
libc _ZNSt3__16threadD1Ev_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1775/1779 (99.78%) 1778/1782 (99.78%) +0.0004%

@github-actions github-actions Bot added the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 21, 2026
@oneandonlydean
oneandonlydean merged commit b8a5ac0 into boykopovar:main Nov 21, 2026
22 checks passed
@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs libc unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants