-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add ability to pin threads #51
Conversation
Hi @fpervaiz! Having the ability to set affinity for a thread in the thread pool is definitely make sense to me, the current main branch of this project lacks such ability. Thank you for coming up with this idea. 👍 Although the idea is great, I have some concerns about the current implementation of the PR.
I thought about it from the other side. Maybe we could provide an event hook for it, letting users do what they want after a thread is spawned and before the worker runs. The specific API still needs to be well-designed. Basically the builder will receive a closure from user, and call it at the beginning of a thread. In this way, What do you think about this? BTW, you can ignore the clippy warnings that are not related to the PR changes in CI failures, I will fix them directly on the main branch later. And thanks for you opening this PR! |
I agree. This is a rather standard way to give the user a chance to glimpse and modify the new thread's environment. Similar to impl ThreadPoolBuilder {
pub fn on_thread_start<F>(&mut self, f: F) -> &mut Self
where
F: Fn() + Sync + 'static,
{
// [...]
}
} |
But for now, I think it's OK to accept this PR and do the refactor in later PRs. The changes proposed in this PR LGTM. |
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.
LGTM.
@Lancern Nice reference! The signature of Considering the concerns about the current @fpervaiz Would you like to continue the PR in this direction? |
Thanks for the input @Lancern @SpriteOvO. I think the |
Adds a feature allowing the pool thread to be pinned to a specific core via
core_affinity