[go: up one dir, main page]

fragile 2.0.1

Provides wrapper types for sending non-send values to other threads.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use std::num::NonZeroUsize;
use std::sync::atomic::{AtomicUsize, Ordering};

fn next() -> NonZeroUsize {
    static COUNTER: AtomicUsize = AtomicUsize::new(1);
    NonZeroUsize::new(COUNTER.fetch_add(1, Ordering::Relaxed))
        .expect("more than usize::MAX threads")
}

pub(crate) fn get() -> NonZeroUsize {
    thread_local!(static THREAD_ID: NonZeroUsize = next());
    THREAD_ID.with(|&x| x)
}