1
use std::cell::Cell;
2
use std::sync::atomic::AtomicUsize;
3
use std::sync::atomic::Ordering;
4

            
5
static THREAD_COUNTER: AtomicUsize = AtomicUsize::new(1);
6

            
7
thread_local! {
8
    static THREAD_ID: Cell<usize> = Cell::new(THREAD_COUNTER.fetch_add(1, Ordering::SeqCst));
9
}
10

            
11
/// Provides a unique number for the current thread.
12
8000004
pub fn thread_id() -> usize {
13
8000004
    THREAD_ID.with(Cell::get)
14
8000004
}