-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Assert a minimum thread count for TaskPoolOptions
#17771
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
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@@ -159,6 +159,7 @@ impl Default for TaskPoolOptions { | |||
impl TaskPoolOptions { | |||
/// Create a configuration that forces using the given number of threads. | |||
pub fn with_num_threads(thread_count: usize) -> Self { | |||
assert!(thread_count > 2); |
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.
This needs a comment about why it's being set; ideally in the message to users.
add panic docstring Co-authored-by: Alice Cecile <[email protected]>
why an
|
I opened this after using the Not sure if Edit: Or a warning, just so the user knows what is happening. |
I would prefer the warning I think. An assert usually means "if the assert fail, it wouldn't have been possible to continue executing the code in a safe way", it's not the case here |
Seconding the warning; I think that's a more appropriate failure level. |
Is it possible to raise a warning (or other message for that matter) from a constructor that is passed to add_plugins, i.e. from .add_plugins(DefaultPlugins.set(TaskPoolPlugin {
task_pool_options: TaskPoolOptions::with_num_threads(4),
})) I've tried both |
I suppose it has to do with both TaskPoolPlugin and LogPlugin being in the DefaultPlugins set, because adding plugins after this can raise log messages using a constructor method. At this point, maybe it's best just to add a note to the documentation of |
You can probably swap the ordering of the two plugins and make this work properly :) |
Updated to a warning.
I can raise the warning if I add plugins separately, but the following does not raise a warning (or any trace, debug, etc.) .add_plugins(DefaultPlugins.set(TaskPoolPlugin { // This does not raise a warning!
task_pool_options: TaskPoolOptions::with_num_threads(1),
})) |
Objective
TaskPool policies assign one thread per group, so three threads are assigned at minimum. Adds an assertion for a minimum thread count for
TaskPoolOptions
. Passing 0, 1 or 2 for thread count has no real effect.Testing