hipthread

Crates.iohipthread
lib.rshipthread
version0.1.2
sourcesrc
created_at2024-12-20 02:20:01.944795
updated_at2025-01-23 12:47:04.854428
descriptionno-std thread library based on pthread
homepage
repositoryhttps://gitcode.com/xuanwu/hipthread
max_upload_size
id1489751
size55,507
hunting (h1467792822)

documentation

README

hipthread

在no-std环境下,封装unix的pthread和mingw的winpthread, 可支持unix和windows.

v0.1.2版本功能

  1. 新增LocalKey<T>: 封装ThrdLocal,更方便使用
static KEY: LocalKey<i32> = LocalKey::new();

fn main() {
    assert!(KEY.get().is_null());
    KEY.set(&101);
    spawn(|| {
        assert!(KEY.get().is_null());
        KEY.set(&102);
    }).unwrap().join();
    assert_eq!(KEY.replace(core::ptr::null()), &101);
}
 

v0.1.1版本功能

  1. 新增LocalRefCell<T>: 提供RefCell<T>类型的TLS变量操作接口
  2. 新增LocalCell<T>: 提供Cell<T>类型的TLS变量操作接口
static LOCAL: LocalCell<i32> = LocalCell::new(|| 100);

fn main() {
    assert_eq!(LOCAL.get(), 100); 
    LOCAL.replace(200);
    let handle = spawn(|| {
        LOCAL.replace(300);
        LOCAL.get()
    }).unwrap();
    assert_eq!(handle.join().unwrap(), 300);
    assert_eq!(LOCAL.get(), 200);
}

v0.1.0版本功能

  1. spawn/spawn_with: 创建线程
  2. ThrdLocal: TLS变量的存取.
  3. Mutex: 互斥锁
  4. Once/OnceLock/LazyLock: 类似std库中的同名类功能.
  5. sched_cpu_count: 获取当前进程可用的核数量.
  6. sched_getaffinity/sched_setaffinity: 设置当前进程同cpu核的亲和性
  7. thrd_setaffinity: 设置当前线程同cpu核的亲和性.
  8. thrd_setname/thrd_getname: 设置获取当前线程的名字,方便调测.
Commit count: 0

cargo fmt