16 unstable releases (4 breaking)

Uses old Rust 2015

0.8.1 Aug 3, 2023
0.8.0 Jan 26, 2023
0.7.6 Dec 1, 2022
0.7.5 Nov 29, 2022
0.5.9 Oct 10, 2017

#19 in Operating systems

Download history 18922/week @ 2023-12-22 23013/week @ 2023-12-29 45709/week @ 2024-01-05 64848/week @ 2024-01-12 73750/week @ 2024-01-19 58100/week @ 2024-01-26 66760/week @ 2024-02-02 63187/week @ 2024-02-09 63830/week @ 2024-02-16 75553/week @ 2024-02-23 80335/week @ 2024-03-01 62530/week @ 2024-03-08 65942/week @ 2024-03-15 72408/week @ 2024-03-22 79791/week @ 2024-03-29 65190/week @ 2024-04-05

295,297 downloads per month
Used in 165 crates (69 directly)

MIT/Apache

20KB
433 lines

core_affinity_rs is a Rust crate for managing CPU affinities. It currently supports Linux, Mac OSX, and Windows.

Documentation

Linux Status Build status

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 std::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 = core_affinity::get_core_ids().unwrap();

// Create a thread for each active CPU core.
let handles = core_ids.into_iter().map(|id| {
    thread::spawn(move || {
        // Pin this thread to a single CPU core.
        let res = core_affinity::set_for_current(id);
        if (res) {
          // Do more work after this.
        }
    })
}).collect::<Vec<_>>();

for handle in handles.into_iter() {
    handle.join().unwrap();
}

Platforms

core_affinity_rs should work on Linux, Windows, Mac OSX, FreeBSD, and Android.

core_affinity_rs is continuously tested on:

  • x86_64-unknown-linux-gnu (Linux)
  • i686-unknown-linux-gnu
  • x86_64-unknown-linux-musl (Linux w/ MUSL)
  • i686-unknown-linux-musl
  • x86_64-apple-darwin (Mac OSX)
  • i686-apple-darwin
  • x86_64-pc-windows-msvc (Windows)
  • i686-pc-windows-msvc
  • x86_64-pc-windows-gnu
  • i686-pc-windows-gnu

core_affinity_rs is continuously cross-compiled for:

  • arm-unknown-linux-gnueabihf
  • aarch64-unknown-linux-gnu
  • mips-unknown-linux-gnu
  • aarch64-unknown-linux-musl
  • i686-linux-android
  • x86_64-linux-android
  • arm-linux-androideabi
  • aarch64-linux-android

Dependencies

~250KB