You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A thread the platform cannot detach ends the process with std::terminate #502
Where the platform cannot detach a thread, the runtime ends the process with std::terminate.
devkitA64's newlib on Switch implements pthread_detach through a libnx hook, __syscall_thread_detach, that libnx does not install (it is commented out as unsupported in nx/source/runtime/newlib.c), so pthread_detach returns ENOSYS. std::thread::detach then throws std::system_error, and the std::thread being destroyed is still joinable, which is std::terminate. That happens at the first Thread.create, and wherever else the runtime starts a thread it detaches:
ThreadImpl_obj::Native's constructor and ThreadImpl_obj::finalise (src/hx/thread/ThreadImpl.cpp)
the collector's worker threads and its release thread (src/hx/gc/Immix.cpp)
the late file closer (src/hx/libs/std/File.cpp) and the process reaper (src/hx/libs/std/Process.cpp)
the profiler and telemetry threads
The file closer, the process reaper and the release thread put the detach in a catch(...), but that never runs for a failed detach: the unwind destroys the joinable std::thread first.
A program can install a hook that returns 0 and does nothing, which stops the abort, but libnx frees a thread only in pthread_join (threadClose and the control block), so every finished thread then leaks its kernel handle and stack until no more can be created.
The runtime cannot reclaim threads on a platform that has no detach, and that belongs to the platform's runtime. It should not end the process, though: when detach fails, the thread should be kept and left to run to its end, as it would detached.
Activity
Keep a thread the platform cannot detach instead of terminating