Repository navigation
fix(libkernel): read and write the detached state of a guest thread atomically - #10810
Conversation
|
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.
|
96fa91d to
4de7905
Compare
4de7905 to
3b1041f
Compare
|
Rebase follow-up: head |
a6aee5f to
b79959c
Compare
|
Windows run of head
AI-assisted: yes (Claude Code); results above were run on this machine. |
…calls on a released thread handle
b79959c to
2567826
Compare
jotitadev
left a comment
There was a problem hiding this comment.
ThreadSanitizer run of head 256782621 (the #10816 commits plus the two #10810 commits) on bare-metal Linux.
Setup: Ubuntu 26.04 x86-64 (i7-8700, not a VM), GCC 15.2, -DANYPS5_ENABLE_TSAN=ON (the option from #11179), RelWithDebInfo, TSAN_OPTIONS=suppressions=tools/tsan-suppressions.txt. I did not bypass the host CPU gate: this CPU passes it. Base: main c3ee5a425; the head merges cleanly. I merged it together with #10100 and #11125 for the run. Those two touch other files and other reports.
Baseline (main c3ee5a425): guest_pthread_stack reports the race in 10 of 10 runs. The read is scePthreadAttrGet (Attr.cpp:97, from RetainedStackWorker). The previous write is scePthreadDetach (Thread.cpp:1137, from main in GuestPthreadStack.cpp:219).
With this PR:
guest_pthread_stackand the newguest_pthread_detach_attr, 10 repeated runs: 0 reports, both pass.guest_pthread_handle_after_exitandguest_pthread_join_detachpass with no report.- Full non-GPU suite: no report from
Pthread/code and no new report in any test.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
What
PthreadPrivate::_detachedwas a plainbool.scePthreadDetachwrites it under the thread's join mutex, whilescePthreadAttrGet,pthread_attr_get_npand the first check of the join path read it with no lock or under a different one. ThreadSanitizer reports this as a data race betweenscePthreadDetachandscePthreadAttrGet(and between detach and join).The field is now
std::atomic<bool>. All existing reads and writes compile unchanged and behave as before; no other change.Tested
Linux x86-64, ThreadSanitizer build (
-fsanitize=thread, RelWithDebInfo, dynamic libstdc++ because TSan cannot link statically). The host CPU gate was bypassed locally for the run only (not committed). No Windows, no ASan/UBSan run for this change, no console hardware.guest_pthread_stacktest already reported the race atAttr.cpp:97(read) againstThread.cpp:1108(write) on currentmain.guest_pthread_detach_attrqueries the attributes of a blocked thread from a second thread while the first detaches it, 50 rounds, and checks the attributes report the detached state afterwards. On currentmainunder TSan it reportsdata race ... in scePthreadDetach; with the fix TSan reports nothing in three runs, andguest_pthread_stackno longer reports it.guest_pthread_join_detachpasses.This PR is stacked on #10816. Rebase follow-up (2026-10-25): it now follows #10816 head
8eaa2bbad58d...on upstreammaina5a780eaaa7f187fe8f5c7f2ef244f6a6dab2762, without conflicts. Both dependency test registrations remain inlibkernel/CMakeLists.txt. Strict GCC C++20 syntax-only checks with-Wall -Wextra -Werrorpassed forThread.cpp(suppressing its existing missing-field-initializer warning) andGuestPthreadDetachAttr.cpp.git diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/main --head HEADpassed. The full local CMake test build could not configure because the SDL2 CMake package is unavailable, so no post-rebase runtime or ThreadSanitizer result is claimed. The reported runtime evidence is from the prior base.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 (none added).mdfiles or images added to the repositoryRebase validation (2026-10-25)
This PR is stacked on updated #10816 head
8eaa2bbad5; #10816 is based on upstreammaina5a780eaaa7f187fe8f5c7f2ef244f6a6dab2762. The rebase completed without conflicts, and both dependency test registrations remain present.git diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/main --head HEADpassed. Full local CMake configuration could not proceed because the SDL2 package is unavailable; no post-rebase runtime or ThreadSanitizer result is claimed.