Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bring back the reader-writer lock for RcwCache - #120675

#120675
Merged
jkoritzinsky merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
jkoritzinsky:rcwcache-rwlock-try2jkoritzinsky/runtime:rcwcache-rwlock-try2Copy head branch name to clipboard
Oct 14, 2025
Merged

Bring back the reader-writer lock for RcwCache#120675
jkoritzinsky merged 2 commits into
dotnet:maindotnet/runtime:mainfrom
jkoritzinsky:rcwcache-rwlock-try2jkoritzinsky/runtime:rcwcache-rwlock-try2Copy head branch name to clipboard

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Instead of writing to _cache while under a reader lock, delay the cleanup until we can acquire a writer lock.

We do this instead of doing an upgradeable lock as ReaderWriterLockSlim only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.

This matches the logic in the .NET 9 CoreCLR implementation of ComWrappers.

Reverts #120370
Fixes #120470

Instead of writing to `_cache` while under a reader lock, delay the cleanup until we can acquire a writer lock.

We do this instead of doing an upgradeable lock as `ReaderWriterLockSlim` only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.

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 reverts a previous change that replaced a ReaderWriterLockSlim with a simple Lock in the RcwCache class, restoring the reader-writer lock mechanism for better concurrency. The change improves the cache's ability to handle concurrent read operations while ensuring thread-safe cleanup of dead entries.

Key changes:

  • Replaces the simple Lock with ReaderWriterLockSlim for the RcwCache
  • Implements a two-phase locking strategy in FindProxyForComInstance to avoid upgradeable locks
  • Updates all cache operations to use appropriate read/write locks with proper try-finally blocks

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

…pServices/ComWrappers.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

[Perf] Linux/x64: 2 Regressions on 10/3/2025 9:18:21 PM +00:00

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.