1 个不稳定版本

使用旧的Rust 2015

0.8.1 2024年3月11日

#186操作系统

Download history 85/week @ 2024-04-08 23/week @ 2024-04-15 88/week @ 2024-04-22 26/week @ 2024-04-29 2/week @ 2024-05-06 187/week @ 2024-05-13 203/week @ 2024-05-20 165/week @ 2024-05-27 221/week @ 2024-06-03 44/week @ 2024-06-10 49/week @ 2024-06-17 77/week @ 2024-06-24 75/week @ 2024-07-01 80/week @ 2024-07-08 164/week @ 2024-07-15 246/week @ 2024-07-22

每月下载量 568
6 个crate中使用 (通过 cpu-utils)

MIT/Apache

24KB
531

core_affinity_rs 是一个用于管理CPU亲和性的Rust crate。它目前支持Linux、Mac OS X和Windows。

文档

Linux Status Build status

示例

此示例展示了如何为每个可用的处理器创建一个线程,并将每个线程固定在其对应的处理器上。

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();
}

平台

core_affinity_rs 应该在Linux、Windows、Mac OS X、FreeBSD和Android上工作。

core_affinity_rs 在以下平台上持续测试

  • 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 OS X)
  • 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 在以下平台上持续交叉编译

  • 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

依赖关系

~28–250KB