Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify thread pool thread counting to be a bit more defensive #70478

Merged
merged 2 commits into from
Jun 9, 2022

Conversation

kouvel
Copy link
Member

@kouvel kouvel commented Jun 9, 2022

  • An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
  • Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
  • Verified by creating an unexpected underflow in the debugger

- An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
- Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
- Verified by creating an unexpected underflow in the debugger
@kouvel kouvel added this to the 7.0.0 milestone Jun 9, 2022
@kouvel kouvel requested review from janvorli and mangod9 June 9, 2022 12:44
@kouvel kouvel self-assigned this Jun 9, 2022
@ghost
Copy link

ghost commented Jun 9, 2022

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details
  • An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
  • Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
  • Verified by creating an unexpected underflow in the debugger
Author: kouvel
Assignees: kouvel
Labels:

area-System.Threading

Milestone: 7.0.0

kouvel added a commit to kouvel/runtime that referenced this pull request Jun 9, 2022
- Port of dotnet#70478 to 6.0
- An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
- Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
- Verified by creating an unexpected underflow in the debugger
set
{
Debug.Assert(value >= 0);
SetInt16Value(value, NumExistingThreadsShift);
SetInt16Value(Math.Max((short)0, value), NumExistingThreadsShift);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be changed to ushort to avoid the Math.Max in multiple places, or is that change going to be too disruptive?

Copy link
Member Author

@kouvel kouvel Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to ushort wouldn't prevent an underflow, a check would still need to ensure that it does not cross zero and wrap around. It may have other undesirable effects in odd cases, probably not worth it.

@kouvel kouvel merged commit 1adda4e into dotnet:main Jun 9, 2022
@kouvel kouvel deleted the PtpCountsDefFix branch June 9, 2022 21:20
carlossanlop pushed a commit that referenced this pull request Jun 11, 2022
…70479)

* [6.0] Modify thread pool thread counting to be a bit more defensive

- Port of #70478 to 6.0
- An unexpected underflow in one or more thread counts can lead to a large number of threads to be created continually
- Prevented underflows in changes to thread counts, such that following an unexpected underflow, subsequent paired increments and decrements would avoid repeating the underflow
- Verified by creating an unexpected underflow in the debugger

* Address feedback
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2022
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.

3 participants