Repository navigation
feat(libkernel): implement thread cancellation - #1141
Conversation
Progress report (948a526 → ef9d0dd)📈 System libraries: 84.51% (+0.07%, +5 implemented functions) ✅ 5 implemented
|
|
Data point: PPSA03306 (Silt, Unity) imports |
|
One thing before this can go in: please drop the |
|
Conflicts with main in |
Refs boykopovar#1668. Complements boykopovar#1141 with resource ownership and lifecycle regressions.
|
Rebased onto current
Rebuilt and ran the libkernel/libs tests on Linux: all green, |
6d38053 to
91ab3f7
Compare
scePthreadCancel and pthread_cancel threw, scePthreadTestcancel did nothing and the cleanup handler exports did not exist. A cancel request is now recorded on the thread and acted on at scePthreadTestcancel, the condition variable waits, scePthreadSem and sem waits, scePthreadJoin and the sleeps, and under their POSIX names. A thread blocked in one of the waits is woken; a condition wait takes its mutex back before the thread exits. The thread exits with PTHREAD_CANCELED through scePthreadExit, which now runs the handlers of __pthread_cleanup_push_imp and __pthread_cleanup_pop_imp. scePthreadSetcancelstate and scePthreadSetcanceltype reject unknown values, and pthread_setcanceltype is added. Constants, the handler node layout and the order of events follow FreeBSD libthr. A sleep is not interrupted, file and socket calls are not cancellation points and the asynchronous type acts like the deferred one except at the two set calls (TechnicalDebt). New test: guest_pthread_cancel.
|
Rebased again onto current Rebuilt and ran the libkernel/libs tests on Linux: all green. |
91ab3f7 to
ef9d0dd
Compare
Refs boykopovar#1668. Complements boykopovar#1141 with resource ownership and lifecycle regressions.
Refs boykopovar#1668. Complements boykopovar#1141 with resource ownership and lifecycle regressions.
What
scePthreadCancelandpthread_cancelthrew,scePthreadTestcanceldid nothing and the cleanup handler exports did not exist (recorded in TechnicalDebt as "Thread cancellation is not modelled"). This implements deferred cancellation after FreeBSD libthr (thr_cancel.c,thr_clean.c,thr_exit.c).scePthreadCancel/pthread_cancelrecord the request on the thread and wake it when it is blocked in a cancellable wait. A null thread returnsESRCH.scePthreadTestcancel, the condition variable waits, thescePthreadSemandsemwaits,scePthreadJoinand the sleeps, and under their POSIX names. A condition wait takes its mutex back before the thread exits, and a cancelled join leaves the target joinable.PTHREAD_CANCELED(1) throughscePthreadExit, which now runs the handlers of the new__pthread_cleanup_push_impand__pthread_cleanup_pop_impexports, newest first. The handler node uses the guest's_pthread_cleanup_infolike libthr'sstruct pthread_cleanup.scePthreadSetcancelstateandscePthreadSetcanceltypereturnEINVALfor unknown values and, like libthr, test for a pending request when the type is asynchronous.pthread_setcanceltypeis added.pthread_cancelmoves fromUnimplemented.cpptoPthread/Posix/Thread.cppwith its real signature.Limits, recorded in TechnicalDebt: a sleep is not interrupted (the thread exits when it ends, so the
sceKernelUsleeppath keeps its timing), file and socket calls are not cancellation points, and the asynchronous type acts like the deferred one except at the two set calls. The constants and the node layout are FreeBSD's, not measured on the console; the NIDs of the two cleanup exports come from their names and I have not seen a title import them.#760 adds three lines to
Pthread.hppandThread.cppin other places; this does not depend on it.Tested
Windows 11, WinLibs GCC 15.2.0: full build,
libstarget andctest(387 passed;agc_driver_sdwa_float_selectors,shader_clock,vop1_float_unary,vop3_mad_i64andvopc_compareexcluded, they fail on this machine's Intel Arc GPU without this change). Newguest_pthread_canceltest cancels threads blocked in a condition wait (while the canceller holds the mutex),scePthreadSemWait,sem_wait,scePthreadJoinand asceKernelUsleeploop, checks the disabled state, the asynchronous type, the handler order and the error codes; it passed 40 runs in a row, and 15 withAPS5_COARSE_TIMED_WAITS=1. Not tested on Linux and not tested with a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)