Repository navigation
Fix a series of possible race conditions in thread static variable initialization - #127843
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
|
Tagging subscribers to this area: @agocke |
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.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
Do we need VolatileLoads to pair with these VolatileWrites? Or are there some hidden invariants that make VolatileLoads unnecessary in these cases? |
|
/ba-g machine timeouts unrelated to this change. |
|
/backport to release/10.0 |
|
Started backporting to |
Fixes #127776