2020-08-29 19:35:41 +00:00
|
|
|
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");
|
2020-11-22 00:38:24 +00:00
|
|
|
let now = instant::Instant::now();
|
|
|
|
while instant::Instant::now() - now < instant::Duration::from_millis(10000) {
|
2020-08-29 19:35:41 +00:00
|
|
|
// spin, simulating work being done
|
|
|
|
}
|
|
|
|
|
|
|
|
println!(
|
|
|
|
"Thread {:?} index {} finished",
|
|
|
|
std::thread::current().id(),
|
|
|
|
i
|
|
|
|
);
|
2022-02-13 22:33:55 +00:00
|
|
|
});
|
2020-08-29 19:35:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
println!("all tasks finished");
|
|
|
|
}
|