mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 13:13:49 +00:00
d8974e7c3d
What is says on the tin. This has got more to do with making `clippy` slightly more *quiet* than it does with changing anything that might greatly impact readability or performance. that said, deriving `Default` for a couple of structs is a nice easy win
31 lines
974 B
Rust
31 lines
974 B
Rust
use bevy_tasks::TaskPoolBuilder;
|
|
|
|
// 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.
|
|
|
|
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::Instant::now();
|
|
while instant::Instant::now() - now < instant::Duration::from_millis(10000) {
|
|
// spin, simulating work being done
|
|
}
|
|
|
|
println!(
|
|
"Thread {:?} index {} finished",
|
|
std::thread::current().id(),
|
|
i
|
|
);
|
|
});
|
|
}
|
|
});
|
|
|
|
println!("all tasks finished");
|
|
}
|