bevy/crates/bevy_tasks/examples/idle_behavior.rs
Carter Anderson 9666a7e688 Rename bevy_platform_support to bevy_platform (#18813)
The goal of `bevy_platform_support` is to provide a set of platform
agnostic APIs, alongside platform-specific functionality. This is a high
traffic crate (providing things like HashMap and Instant). Especially in
light of https://github.com/bevyengine/bevy/discussions/18799, it
deserves a friendlier / shorter name.

Given that it hasn't had a full release yet, getting this change in
before Bevy 0.16 makes sense.

- Rename `bevy_platform_support` to `bevy_platform`.
2025-04-14 22:45:27 +02:00

36 lines
1.1 KiB
Rust

//! This sample demonstrates a thread pool with one thread per logical core and only one task
//! spinning. Other than the one thread, the system should remain idle, demonstrating good behavior
//! for small workloads.
#![expect(clippy::print_stdout, reason = "Allowed in examples.")]
use bevy_platform::time::Instant;
use bevy_tasks::TaskPoolBuilder;
use core::time::Duration;
fn main() {
let pool = TaskPoolBuilder::new()
.thread_name("Idle Behavior ThreadPool".to_string())
.build();
pool.scope(|s| {
for i in 0..1 {
s.spawn(async move {
println!("Blocking for 10 seconds");
let now = Instant::now();
while Instant::now() - now < Duration::from_millis(10000) {
// spin, simulating work being done
}
println!(
"Thread {:?} index {} finished",
std::thread::current().id(),
i
);
});
}
});
println!("all tasks finished");
}