Skip to content

Conversation

jkoritzinsky
Copy link
Member

Fixes #118293

Primarily done via Copilot based on the issue (just done locally on a Windows machine to avoid the problems with #118302)

Copy link
Contributor

@Copilot 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 PR implements Thread.Interrupt functionality for NativeAOT on Windows, addressing issue #118293. The implementation enables thread interruption through Windows APC (Asynchronous Procedure Call) mechanism.

Key changes:

  • Adds native interrupt APC callback and thread state management in the NativeAOT runtime
  • Implements Thread.Interrupt() and CheckForPendingInterrupt() methods for Windows
  • Integrates interrupt checks into sleep and wait operations with alertable waits
  • Removes conditional test exclusions for NativeAOT now that Thread.Interrupt is supported

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tests/baseservices/threading/regressions/115178/115178.cs Removes NativeAOT conditional exclusion for interrupt test
src/libraries/System.Threading/tests/MonitorTests.cs Removes ActiveIssue attribute excluding NativeAOT from interrupt wait test
src/libraries/System.Threading.Thread/tests/ThreadTests.cs Removes ActiveIssue attributes excluding NativeAOT from interrupt tests
src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.Windows.cs Adds interrupt checks during APC completion in wait operations
src/libraries/System.Private.CoreLib/src/System/Threading/Thread.Windows.cs Changes conditional compilation to exclude Mono instead of including CoreCLR
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Threading.cs Adds P/Invoke declarations for QueueUserAPC and SleepEx
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs Adds Interrupted thread state constant
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs Implements Thread.Interrupt, SleepInternal, and interrupt-aware join operations
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs Adds runtime imports for interrupt APC callback and interrupt checking
src/coreclr/nativeaot/Runtime/thread.h Adds TSF_Interrupted thread state flag and interrupt management methods
src/coreclr/nativeaot/Runtime/thread.cpp Implements interrupt state management and native APC callback functions

Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM otherwise. Thank you!

@MichalStrehovsky
Copy link
Member

Please don't forget to run outerloop when this is ready to merge, I don't think we run any of these newly enabled tests by default.

…ore throwing the exception instead of in a finally block
@jkoritzinsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/ba-g nativeaot linux failures and windows timeout seem unrelated. Tests passed on the windows leg (manually inspected the test results on the job that completed right before the timeout)

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) August 28, 2025 01:34
@jkoritzinsky jkoritzinsky merged commit c09afe1 into dotnet:main Aug 28, 2025
164 of 168 checks passed
@jkoritzinsky jkoritzinsky deleted the thread-interrupt-naot branch August 28, 2025 01:34
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.

[NativeAOT] Thread.Interrupt not implemented on Windows
3 participants