core_affinity_rs is a Rust crate for managing CPU affinities. It currently supports Linux, Mac OSX, and Windows.
Example
This example shows how create a thread for each available processor and pin each thread to its corresponding processor.
extern crate core_affinity;
use thread;
// Retrieve the IDs of all cores on which the current
// thread is allowed to run.
// NOTE: If you want ALL the possible cores, you should
// use num_cpus.
let core_ids = get_core_ids.unwrap;
// Create a thread for each active CPU core.
let handles = core_ids.into_iter.map.;
for handle in handles.into_iter
Platforms
core_affinity_rs should work on Linux, Windows, Mac OSX, and Android.
core_affinity_rs is continuously tested on:
x86_64-unknown-linux-gnu(Linux)i686-unknown-linux-gnux86_64-unknown-linux-musl(Linux w/ MUSL)i686-unknown-linux-muslx86_64-apple-darwin(Mac OSX)i686-apple-darwinx86_64-pc-windows-msvc(Windows)i686-pc-windows-msvcx86_64-pc-windows-gnui686-pc-windows-gnu
core_affinity_rs is continuously cross-compiled for:
arm-unknown-linux-gnueabihfaarch64-unknown-linux-gnumips-unknown-linux-gnuaarch64-unknown-linux-musli686-linux-androidx86_64-linux-androidarm-linux-androideabiaarch64-linux-android