-
Notifications
You must be signed in to change notification settings - Fork 651
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
Conversation
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
Sources/NIOPosix/NIOThreadPool.swift
Outdated
case .shuttingDown, .stopped: | ||
return [] | ||
return (unlockWith: .hasWork, result: []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this state right?
There was a problem hiding this comment.
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.
Sources/NIOPosix/NIOThreadPool.swift
Outdated
case .shuttingDown, .stopped: | ||
return body | ||
workState = .hasWork |
There was a problem hiding this comment.
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.
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:
Result: