pub fn set_thread_affinity<B: AsRef<[usize]>>(
core_ids: B,
) -> Result<(), Box<dyn Error>>Expand description
Binds the current thread to the specified core(s)
Examples found in repository?
examples/main.rs (line 21)
16pub fn main() -> Result<(), Box<dyn Error>> {
17 println!("Total cores : {}", get_core_num());
18
19 let cores = (0..get_core_num()).step_by(2).collect::<Vec<usize>>();
20 println!("Binding thread to cores : {:?}", &cores);
21 set_thread_affinity(&cores)?;
22
23 let bound_cores = get_thread_affinity()?;
24 println!("\tCurrent thread affinity : {:?}", bound_cores);
25 println!("\tTotal cores : {}", get_core_num());
26
27 assert_eq!(bound_cores, cores.as_slice());
28
29 #[cfg(target_os = "windows")]
30 bind_process()?;
31
32 Ok(())
33}