Skip to content

Release pthread runtime resources during PSP module teardown - #4

Open
DublikuntMux wants to merge 2 commits into
pspdev:platform_agnosticfrom
DublikuntMux:psp-module-cleanup
Open

DublikuntMux wants to merge 2 commits into
pspdev:platform_agnosticfrom
DublikuntMux:psp-module-cleanup

Conversation

@DublikuntMux

@DublikuntMux DublikuntMux commented Nov 6, 2026 •

Copy link
Copy Markdown

PSP module shutdown leaks pthread runtime resources: the implicit native main-thread handle, cached thread records and six global mutex semaphores survive termination. Mutex initialization also reports success when semaphore creation fails. C++ recursive mutex wrappers additionally omit native destruction because the public pthread header only selects GCC's ordinary-mutex initialization path.

Release the implicit thread record without deleting the native main thread, reset the reuse pool, and destroy global locks after key/thread cleanup. Propagate semaphore creation failure as EAGAIN and free the partially initialized mutex. Select _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC alongside the existing ordinary flag so C++ recursive wrappers release their resources using GCC's existing generic implementation. Add C++11 destructor-trait assertions for ordinary, timed, recursive and recursive-timed mutexes.

Applications must finish/join explicit POSIX workers before calling pthread_terminate. This targets platform_agnostic, the branch used by the PSP toolchain. Complete PSP module cleanup also needs PSPSDK PR #408, which invokes teardown before releasing the heap and cleans up PSP OSAL resources.

Release the implicit native main-thread pthread handle without deleting its OS thread. Clear the thread-reuse pool and destroy all six global mutex semaphores after key and thread cleanup.

Propagate semaphore allocation failure from pthread_mutex_init rather than returning an invalid mutex. Applications must join their explicit workers before terminating the runtime.
Match the existing ordinary-mutex gthread selection for recursive mutexes. Both static initializers defer native resource allocation; libstdc++ wrappers must still run native destruction after use. Keep this implementation policy in pthread rather than adding PSP-specific code to GCC.

Add C++11 destructor-trait coverage for ordinary, timed, recursive and recursive-timed mutexes. With unmodified GCC gthread code, the old header fails recursive assertions and this header passes all four.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant