Fix a series of possible race conditions in thread static variable initialization#127843
Merged
davidwrighton merged 7 commits intoMay 13, 2026
Merged
Conversation
…itialization - The two critical ones are the one just after the memcpy in the TLSIndexToMethodTableMap, as well as the VolatileStore when setting pIndex. Fixes dotnet#127776
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets a set of suspected race conditions in CoreCLR thread-static infrastructure by strengthening publication/visibility guarantees when updating TLS index metadata and the TLSIndex→MethodTable map. This aligns with the reported intermittent macOS arm64 crash in GetThreadLocalStaticBase by ensuring readers can’t observe partially-published state during concurrent thread-static access.
Changes:
- Use
VolatileStorewhen publishing a resizedTLSIndexToMethodTableMap(pMapandm_maxIndex) to ensure the copied/initialized map contents are visible before other threads observe the updated pointers/sizes. - Use
VolatileStorewhen writing/clearing individual map entries to prevent reordering and improve cross-thread visibility of per-index updates. - Use
VolatileStorewhen publishing the newly allocatedTLSIndex(*pIndex) so other threads that observe the allocated index have the intended ordering/visibility for preceding writes on the allocation path.
3 tasks
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Member
|
Do we need VolatileLoads to pair with these VolatileWrites? Or are there some hidden invariants that make VolatileLoads unnecessary in these cases? |
VSadov
reviewed
May 11, 2026
VSadov
reviewed
May 11, 2026
VSadov
reviewed
May 11, 2026
VSadov
reviewed
May 11, 2026
Open
3 tasks
This was referenced May 12, 2026
Member
Author
|
/ba-g machine timeouts unrelated to this change. |
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.
Fixes #127776