Skip to content

Commit

Permalink
Quick fix for bevyengine#405 (bevyengine#408)
Browse files Browse the repository at this point in the history
- Use saturating_sub to avoid overflow in core assignment to task pools
- Temporarily force 4 minimum threads to avoid examples stalling
  • Loading branch information
aclysma authored and mrk-its committed Oct 6, 2020
1 parent 7b2da82 commit 6d7f01d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/bevy_app/src/task_pool_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Default for DefaultTaskPoolOptions {
fn default() -> Self {
DefaultTaskPoolOptions {
// By default, use however many cores are available on the system
min_total_threads: 1,
min_total_threads: 4, // TODO(#408): set `min_total_threads` back to `1`
max_total_threads: std::usize::MAX,

// Use 25% of cores for IO, at least 1, no more than 4
Expand Down Expand Up @@ -96,6 +96,7 @@ impl DefaultTaskPoolOptions {
self.min_total_threads,
self.max_total_threads,
);
log::trace!("Assigning {} cores to default task pools", total_threads);

let mut remaining_threads = total_threads;

Expand All @@ -104,7 +105,9 @@ impl DefaultTaskPoolOptions {
let io_threads = self
.io
.get_number_of_threads(remaining_threads, total_threads);
remaining_threads -= io_threads;

log::trace!("IO Threads: {}", io_threads);
remaining_threads = remaining_threads.saturating_sub(io_threads);

resources.insert(IOTaskPool(
TaskPoolBuilder::default()
Expand All @@ -119,7 +122,9 @@ impl DefaultTaskPoolOptions {
let async_compute_threads = self
.async_compute
.get_number_of_threads(remaining_threads, total_threads);
remaining_threads -= async_compute_threads;

log::trace!("Async Compute Threads: {}", async_compute_threads);
remaining_threads = remaining_threads.saturating_sub(async_compute_threads);

resources.insert(AsyncComputeTaskPool(
TaskPoolBuilder::default()
Expand All @@ -136,6 +141,7 @@ impl DefaultTaskPoolOptions {
.compute
.get_number_of_threads(remaining_threads, total_threads);

log::trace!("Compute Threads: {}", compute_threads);
resources.insert(ComputeTaskPool(
TaskPoolBuilder::default()
.num_threads(compute_threads)
Expand Down

0 comments on commit 6d7f01d

Please sign in to comment.