Skip to content

Conversation

@eduardo-vp
Copy link
Member

@eduardo-vp eduardo-vp commented Mar 27, 2025

Fixes #107077.

Copilot AI review requested due to automatic review settings March 27, 2025 18:54
Copy link
Contributor

Copilot AI left a comment

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 updates the WaitingWriteCount property in ReaderWriterLockSlim so that it includes the thread potentially waiting in upgradable mode, addressing issue #107077.

  • Added a comment explaining the inclusion of upgradable mode waiters.
  • Adjusted the WaitingWriteCount property to sum _numWriteWaiters and _numWriteUpgradeWaiters.
Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/src/System/Threading/ReaderWriterLockSlim.cs:1416

  • Verify that _numWriteWaiters and _numWriteUpgradeWaiters are updated under the same concurrency control mechanism to prevent potential race conditions when summing their values.
public int WaitingWriteCount => (int)_numWriteWaiters + (int)_numWriteUpgradeWaiters;

@eduardo-vp eduardo-vp force-pushed the fix-ReaderWriterLockSlim-WaitingWriteCount branch from bc7881b to 4457707 Compare March 28, 2025 17:37
@eduardo-vp
Copy link
Member Author

/ba-g Test failures are not related to this change.

@eduardo-vp eduardo-vp merged commit ddd44f2 into dotnet:main Mar 31, 2025
139 of 143 checks passed
@eduardo-vp eduardo-vp deleted the fix-ReaderWriterLockSlim-WaitingWriteCount branch March 31, 2025 17:53
thaystg pushed a commit to thaystg/runtime that referenced this pull request Apr 1, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 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.

ReaderWriterLockSlim.WaitingWriteCount returns 0 if the write lock is entering as an upgrade from UpgradableReadLock

3 participants