Skip to content

Add a lock to GetNewThunksBlock#119267

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:fix116089
Sep 3, 2025
Merged

Add a lock to GetNewThunksBlock#119267
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:fix116089

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Fixes #116089.

The method accesses shared static state, locking is needed.

Cc @dotnet/ilc-contrib

Fixes dotnet#116089.

The method accesses shared static state, locking is needed.
Copilot AI review requested due to automatic review settings September 2, 2025 13:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds thread safety to the GetNewThunksBlock method by introducing a lock to protect access to shared static state. The issue was that multiple threads could concurrently access and modify the static fields s_currentlyMappedThunkBlocks and s_currentlyMappedThunkBlocksIndex without synchronization, leading to potential race conditions.

Key changes:

  • Adds a static Lock field for synchronization
  • Wraps the GetNewThunksBlock method body with lock acquisition using the new Lock.Scope pattern
  • Imports the System.Threading namespace to support the locking functionality

Comment thread src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/ThunkPool.cs Outdated
…e/ThunkPool.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@MichalStrehovsky MichalStrehovsky merged commit e4df9f3 into dotnet:main Sep 3, 2025
93 of 96 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix116089 branch September 3, 2025 13:13
filipnavara pushed a commit to filipnavara/runtime that referenced this pull request Sep 5, 2025
Fixes dotnet#116089.

The method accesses shared static state, locking is needed.
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition creating thunkpools

4 participants