Skip to content

Remove dead thread suspension code from PAL#124049

Merged
jkotas merged 15 commits intomainfrom
copilot/remove-dead-code-semaphore
Feb 6, 2026
Merged

Remove dead thread suspension code from PAL#124049
jkotas merged 15 commits intomainfrom
copilot/remove-dead-code-semaphore

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Summary

Successfully removed dead code related to thread suspension and thread list maintenance from the PAL:

  • Total lines removed: ~1,200+ lines of dead code
  • Files changed: 13 files
  • Build status: ✅ Success (all builds passing)

The PAL implementation is significantly cleaner with a single unified code path for thread suspension using pthread mutexes across all platforms.

Original prompt

Create PR to delete dead code related to thread suspension from under src\coreclr\pal\src. Methods like PostOnSuspendSemaphore, WaitOnSuspendSemaphore, etc. are dead code. Also, make sure to delete all defines like HAS_POSIX_SEMAPHORES that become unused once this code is deleted


💡 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.

- 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>
Copilot AI changed the title [WIP] Remove dead code related to thread suspension from coreclr Remove dead thread suspension semaphore code from PAL Feb 5, 2026
Copilot AI requested a review from jkotas February 5, 2026 15:37
…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>
Copilot AI changed the title Remove dead thread suspension semaphore code from PAL Remove dead thread suspension code from PAL Feb 5, 2026
- 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>
@jkotas
Copy link
Member

jkotas commented Feb 5, 2026

@copilot Delete PROCGetNumberOfThreads

@jkotas
Copy link
Member

jkotas commented Feb 5, 2026

@copilot Delete pGThreadList and the code that maintains it. It does not seem to be used for anything

@jkotas
Copy link
Member

jkotas commented Feb 5, 2026

@delete SignalHandlerThread . It is not used

@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

@copilot Try again

@jkotas jkotas marked this pull request as ready for review February 6, 2026 02:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

jkotas and others added 2 commits February 5, 2026 18:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AaronRobinsonMSFT
Copy link
Member

@copilot Please verify none of these APIs are used in the pal tests under src/coreclr/pal/tests/palsuite

@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

/azp run runtime-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas Unclear what is going on with copilot right now. I'm sure you'll do all the validation, :shipit:

@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

Unclear what is going on with copilot right now.

It got tired of deleting dead PAL code. I do not see problems in other PRs.

PALTests are passing except for one known issue.

@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

/ba-g known issue #122345 that is not matched by build analysis for some reason

@jkotas jkotas merged commit 8214ffd into main Feb 6, 2026
191 of 208 checks passed
@jkotas jkotas deleted the copilot/remove-dead-code-semaphore branch February 6, 2026 07:11
lewing pushed a commit to lewing/runtime that referenced this pull request Feb 9, 2026
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants