Skip to main content

get

Function get 

Source
pub fn get() -> usize
Expand description

Returns the number of available CPUs of the current system.

This function will get the number of logical cores. Sometimes this is different from the number of physical cores (See Simultaneous multithreading on Wikipedia).

This will always return at least 1.

§Examples

let cpus = num_cpus::get();
if cpus > 1 {
    println!("We are on a multicore system with {} CPUs", cpus);
} else {
    println!("We are on a single core system");
}

§Note

This delegates to std::thread::available_parallelism. On Linux and other supported platforms that accounts for the current thread’s CPU affinity mask as well as CPU quotas enforced by cgroups, so it may report fewer CPUs than are physically present.