coreclr: implement Environment.CurrentManagedThreadId via ManagedThreadId.Current#129954
Draft
Copilot wants to merge 2 commits into
Draft
coreclr: implement Environment.CurrentManagedThreadId via ManagedThreadId.Current#129954Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
….Current on CoreCLR
On CoreCLR, `t_currentManagedThreadId` is set up by the type system to
point to a special location populated with the thread's managed ID before
any managed caller can observe it (the thin-lock implementation already
relies on this guarantee).
This change makes `Environment.CurrentManagedThreadId` simply delegate to
`ManagedThreadId.Current`, turning an FCall into a cheap thread-static
read, aligning CoreCLR with NativeAOT/Mono which already do the same.
- Environment.CoreCLR.cs: replace InternalCall property with
`=> Threading.ManagedThreadId.Current`
- ecalllist.h: remove the now-unused
`FCFuncElement("get_CurrentManagedThreadId", JIT_GetCurrentManagedThreadId)`
`JIT_GetCurrentManagedThreadId` is kept in jithelpers.cpp and
jitinterface.h because it is still needed as the native entry point for
the JIT helper `CORINFO_HELP_GETCURRENTMANAGEDTHREADID` (used by the JIT
when optimizing `Thread.CurrentThread.ManagedThreadId`).
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update Environment.CurrentManagedThreadId to return ManagedThreadId.Current
coreclr: implement Environment.CurrentManagedThreadId via ManagedThreadId.Current
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On CoreCLR,
Environment.CurrentManagedThreadIdwas backed by an FCall (JIT_GetCurrentManagedThreadId→GetThread()->GetThreadId()).ManagedThreadId.Currentreadst_currentManagedThreadId, a[ThreadStatic]wired by the type system to a special location that is populated with the thread's managed ID before any managed caller can observe it — the thin-lock implementation already depends on this guarantee.This makes
Environment.CurrentManagedThreadIda plain thread-static read on CoreCLR, matching what NativeAOT and Mono already do.Changes
Environment.CoreCLR.cs: replace[MethodImpl(MethodImplOptions.InternalCall)]extern property with=> Threading.ManagedThreadId.Currentecalllist.h: removeFCFuncElement("get_CurrentManagedThreadId", JIT_GetCurrentManagedThreadId)fromgEnvironmentFuncsJIT_GetCurrentManagedThreadId(jithelpers.cpp/jitinterface.h) is kept: it remains the native entry point for theCORINFO_HELP_GETCURRENTMANAGEDTHREADIDJIT helper (used when optimizingThread.CurrentThread.ManagedThreadId)