pub fn available_concurrency() -> Result<NonZeroUsize>
Returns the number of hardware threads available to the program.
This value should be considered only a hint.
If interpreted as the number of actual hardware threads, it may undercount on Windows systems with more than 64 hardware threads. If interpreted as the available concurrency for that process, it may overcount on Windows systems when limited by a process wide affinity mask or job object limitations, and it may overcount on Linux systems when limited by a process wide affinity mask or affected by cgroups limits.
This function will return an error in the following situations, but is not limited to just these cases:
- If the number of hardware threads is not known for the target platform.
- The process lacks permissions to view the number of hardware threads available.
#![feature(available_concurrency)] use std::thread; let count = thread::available_concurrency().map(|n| n.get()).unwrap_or(1);Run