Repository navigation
Unify Thread.CurrentOSThreadId between CoreCLR and NativeAOT - #135144
Conversation
Implement CurrentOSThreadId in shared Thread.cs on top of existing interop (Kernel32.GetCurrentThreadId on Windows, SystemNative_GetUInt64OSThreadId elsewhere) and delete the CoreCLR ThreadNative_GetCurrentOSThreadId QCall and the NativeAOT RhCurrentOSThreadId FCALL. Mark GetUInt64OSThreadId with SuppressGCTransition, and make the WASI stub return 1 (single thread) instead of asserting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac6fb33d-fc74-41c7-a804-75fbf616b155
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Cross-runtime interop changes need platform validation and human review, particularly for WASI and NativeAOT fail-fast consumers; builds and tests were not run.
Review effort: Balanced
Findings: None
What changed in this PR
Unifies Thread.CurrentOSThreadId across CoreCLR and NativeAOT through shared platform interop, while preserving Mono’s implementation.
Changes:
- Routes Windows and Unix thread-ID queries through shared interop.
- Removes redundant runtime entry points and declarations.
- Returns thread ID
1for single-threaded WASI.
| File | Description |
|---|---|
| src/native/libs/System.Native/pal_threading_wasi.c | Returns the single-threaded WASI ID. |
| src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs | Shares platform-specific thread-ID dispatch. |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs | Broadens 64-bit interop availability and suppresses GC transitions. |
| src/coreclr/vm/qcallentrypoints.cpp | Removes the obsolete QCall registration. |
| src/coreclr/vm/comsynchronizable.h | Removes the obsolete QCall declaration. |
| src/coreclr/vm/comsynchronizable.cpp | Removes the CoreCLR-specific implementation. |
| src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs | Removes the managed QCall import. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs | Removes the NativeAOT-specific property. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs | Removes the unused runtime import. |
| src/coreclr/nativeaot/Runtime/thread.cpp | Removes the NativeAOT native entry point. |
…lpers - Move CurrentOSThreadId into Thread.Windows.cs / Thread.Unix.cs and let Mono use it too (drop the Mono GetCurrentOSThreadId icall, which returned the same values). - Rename SystemNative_GetUInt64OSThreadId to SystemNative_GetOSThreadId and delete the unused SystemNative_TryGetUInt32OSThreadId. - Use minipal_get_current_thread_id in the WASI shim. - Delete unused RhCurrentNativeThreadId. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac6fb33d-fc74-41c7-a804-75fbf616b155
|
@jkotas thanks for the fb, addressed |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8acd7b8c-9618-46e1-8654-0e1b27b4480a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1605c6d9-7fb1-4846-bd10-06628c6bf2ea
|
@lewing Could you please take a look at System.Threading.Tasks failure on Wasm? I am not able to tell whether it was somehow caused by the PR changes (the PR is changing threading, so there may be some connection). |
|
@EgorBo I think this may need https://github.com/dotnet/runtime/blob/main/src/coreclr/vm/wasm/generate-coreclr-helpers.cmd to fix the wasm failure. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e652426b-8668-4590-b10e-94bbe6edf26c
|
Merge conflicts |
|
Ah, oops. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec60cb09-d94b-427d-886d-cac926a87fbb
a84cbba to
f487daf
Compare
No description provided.