Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/bevy_app/src/task_pool_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use alloc::string::ToString;
use bevy_platform_support::sync::Arc;
use bevy_tasks::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool, TaskPoolBuilder};
use core::{fmt::Debug, marker::PhantomData};
use log::trace;
use log::{trace, warn};

#[cfg(not(target_arch = "wasm32"))]
use {crate::Last, bevy_ecs::prelude::NonSend};
Expand Down Expand Up @@ -158,7 +158,14 @@ impl Default for TaskPoolOptions {

impl TaskPoolOptions {
/// Create a configuration that forces using the given number of threads.
///
/// Warns for values below 3 as three minimum are needed for the default pool assignments (IO, Async and Compute pools each need at least one thread).
pub fn with_num_threads(thread_count: usize) -> Self {
if thread_count < 3 {
warn!(
"The default TaskPoolOptions thread assignment policies require a minimum of one thread each for the IO, Async, and Compute pools. Three threads will be assigned."
);
}
TaskPoolOptions {
min_total_threads: thread_count,
max_total_threads: thread_count,
Expand Down