#thread #pthreads #no-std #mingw

no-std hipthread

no-std thread library based on pthread

4 releases

0.1.3 Feb 7, 2025
0.1.2 Jan 23, 2025
0.1.1 Jan 23, 2025
0.1.0 Dec 20, 2024

#417 in Concurrency

Download history 126/week @ 2024-12-17 225/week @ 2025-01-21 5/week @ 2025-01-28 142/week @ 2025-02-04 17/week @ 2025-02-11

389 downloads per month
Used in hirun

MIT/Apache

45KB
1K SLoC

hipthread

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

v0.1.3版本更新

消除只支持***-pc-windows-gnu的约束,也可以支持***-pc-windows-msvc, 只是运行时依赖mingwlibwinpthread-1.dll.

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: 设置获取当前线程的名字,方便调测.

Dependencies

~175KB