Remove dead thread suspension code from PAL#124049
Conversation
- Removed unused methods: PostOnSuspendSemaphore, WaitOnSuspendSemaphore, PostOnResumeSemaphore, WaitOnResumeSemaphore - Removed semaphore member variables from CThreadSuspensionInfo class - Removed DestroySemaphoreIds method and PROCCleanupThreadSemIds function - Removed USE_POSIX_SEMAPHORES, USE_SYSV_SEMAPHORES, USE_PTHREAD_CONDVARS defines - Removed HAS_POSIX_SEMAPHORES configuration checks - Simplified InitializePreCreate to just return NO_ERROR Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
…N_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX - Removed SetSuspendedForShutdown/GetSuspendedForShutdown and m_fSuspendedForShutdown (only used in debug trace) - Removed DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX define and always use pthread mutex path - Removed spinlock implementation (SPINLOCKInit, SPINLOCKAcquire, SPINLOCKRelease, SPINLOCKTryAcquire) - Simplified thread suspension to always use pthread mutexes on all platforms Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
- Removed unused MAX_TRACKED_CRITSECS define from threadsusp.hpp Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
…Thread, USE_GLOBAL_LOCK_FOR_SUSPENSION - Removed m_fPending member variable and SetSuspPending/GetSuspPending methods (never called) - Removed m_lNumThreadsSuspendedByThisThread debug variable and related methods (never called) - Removed USE_GLOBAL_LOCK_FOR_SUSPENSION conditional compilation (never defined) - Simplified suspension lock code by removing all dead conditional branches Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
@copilot Delete PROCGetNumberOfThreads |
|
@copilot Delete pGThreadList and the code that maintains it. It does not seem to be used for anything |
|
@delete SignalHandlerThread . It is not used |
|
@copilot Try again |
There was a problem hiding this comment.
Pull request overview
This pull request removes approximately 1,200 lines of dead code related to thread suspension and thread list maintenance from the Platform Abstraction Layer (PAL). The changes consolidate thread suspension to use a single unified code path with pthread mutexes across all platforms.
Changes:
- Removed multiple thread suspension synchronization mechanisms (POSIX semaphores, SysV semaphores, pthread condition variables, and spinlocks) in favor of a single pthread mutex-based approach
- Removed thread list management infrastructure (PROCAddThread, PROCRemoveThread, PROCProcessLock, PROCProcessUnlock, global thread list)
- Removed associated CMake configuration tests and defines (HAS_POSIX_SEMAPHORES, DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX, PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO, USE_GLOBAL_LOCK_FOR_SUSPENSION)
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/pal/src/thread/threadsusp.cpp | Removed ~450 lines: spinlock implementation, global suspension lock, semaphore-based Post/Wait functions (PostOnSuspendSemaphore, WaitOnSuspendSemaphore, PostOnResumeSemaphore, WaitOnResumeSemaphore), SysV semaphore cleanup, and associated conditional compilation blocks |
| src/coreclr/pal/src/thread/thread.cpp | Removed thread list management during thread creation/destruction and errno preservation code around pthread_create |
| src/coreclr/pal/src/thread/procprivate.hpp | Removed function declarations for PROCAddThread, PROCRemoveThread, PROCGetNumberOfThreads |
| src/coreclr/pal/src/thread/process.cpp | Removed ~200 lines: PROCAddThread, PROCRemoveThread, PROCGetNumberOfThreads, PROCProcessLock, PROCProcessUnlock, PROCCleanupThreadSemIds, PROCDumpThreadList, global thread list variables (pGThreadList, g_dwThreadCount, g_csProcess), and simplified InitializeProcessData/PROCCleanupInitialProcess |
| src/coreclr/pal/src/init/sxs.cpp | Removed PROCAddThread call in AllocatePalThread |
| src/coreclr/pal/src/init/pal.cpp | Removed PROCAddThread call and PROCDumpThreadList debug call |
| src/coreclr/pal/src/include/pal/threadsusp.hpp | Removed ~100 lines: semaphore member variables, suspension state tracking members (m_fPending, m_fSuspendedForShutdown, m_lNumThreadsSuspendedByThisThread), spinlock members, and associated getter/setter methods |
| src/coreclr/pal/src/include/pal/process.h | Removed PROCCleanupThreadSemIds, PROCProcessLock, PROCProcessUnlock function declarations |
| src/coreclr/pal/src/configure.cmake | Removed CMake tests for PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO, HAS_POSIX_SEMAPHORES, and DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX platform-specific defines |
| src/coreclr/pal/src/config.h.in | Removed cmakedefine directives for PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO, HAS_POSIX_SEMAPHORES, DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX |
| eng/native/tryrun_ios_tvos.cmake | Removed cache value settings for HAS_POSIX_SEMAPHORES, PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO |
| eng/native/tryrun.cmake | Removed cache value settings for HAS_POSIX_SEMAPHORES, PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO |
| eng/native/tryrun.browser.cmake | Removed cache value settings for HAS_POSIX_SEMAPHORES, PTHREAD_CREATE_MODIFIES_ERRNO, SEM_INIT_MODIFIES_ERRNO |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot Please verify none of these APIs are used in the pal tests under src/coreclr/pal/tests/palsuite |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
@jkotas Unclear what is going on with copilot right now. I'm sure you'll do all the validation, ![]()
It got tired of deleting dead PAL code. I do not see problems in other PRs. PALTests are passing except for one known issue. |
|
/ba-g known issue #122345 that is not matched by build analysis for some reason |
Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Successfully removed dead code related to thread suspension and thread list maintenance from the PAL:
The PAL implementation is significantly cleaner with a single unified code path for thread suspension using pthread mutexes across all platforms.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.