1 个不稳定版本
使用旧的Rust 2015
| 0.8.1 | 2024年3月11日 |
|---|
#186 在 操作系统
每月下载量 568
在 6 个crate中使用 (通过 cpu-utils)
24KB
531 行
core_affinity_rs 是一个用于管理CPU亲和性的Rust crate。它目前支持Linux、Mac OS X和Windows。
示例
此示例展示了如何为每个可用的处理器创建一个线程,并将每个线程固定在其对应的处理器上。
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-gnux86_64-unknown-linux-musl(Linux w/ MUSL)i686-unknown-linux-muslx86_64-apple-darwin(Mac OS X)i686-apple-darwinx86_64-pc-windows-msvc(Windows)i686-pc-windows-msvcx86_64-pc-windows-gnui686-pc-windows-gnu
core_affinity_rs 在以下平台上持续交叉编译
arm-unknown-linux-gnueabihfaarch64-unknown-linux-gnumips-unknown-linux-gnuaarch64-unknown-linux-musli686-linux-androidx86_64-linux-androidarm-linux-androideabiaarch64-linux-android
依赖关系
~28–250KB