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

Use condition variable in NIOThreadPool #2964

Merged
merged 7 commits into from
Nov 19, 2024

Conversation

glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Nov 6, 2024

Motivation:

The thread performance checker warns that a threads with QoS are waiting on threads in the NIOThreadPool. We can avoid these warnings by using a condition variable instead.

Modifications:

  • Replace the usage of a semaphore and lock in NIOThreadPool with a condition lock.
  • The condition value indicates whether the threads have work to do (where work is processing work items or exiting their run loop).

Result:

Motivation:

The thread performance checker warns that a threads with QoS are waiting
on threads in the NIOThreadPool. We can avoid these warnings by using a
condition variable instead.

Modifications:

- Replace the usage of a semaphore and lock in NIOThreadPool with a
  condition lock.
- The condition value indicates whether the threads have work to do
  (where work is processing work items or exiting their run loop).

Result:

Fewer warnings
@glbrntt glbrntt added the semver/patch No public API change. label Nov 6, 2024
@glbrntt glbrntt requested a review from Lukasa November 7, 2024 13:37
case .shuttingDown, .stopped:
return []
return (unlockWith: .hasWork, result: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this state right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I don't think we need to unlock with a value here, if we're already shutting down then we've already signalled there's work for the threads to do, we don't need to do that again.

case .shuttingDown, .stopped:
return body
workState = .hasWork
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here. It might be useful to write out the strategy for the lock value in a comment above it, which will make it easier to audit.

@glbrntt glbrntt requested a review from Lukasa November 11, 2024 16:11
@Lukasa Lukasa merged commit af0e612 into apple:main Nov 19, 2024
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NIOFileSystem operations thread warnings
2 participants