Expand description

Efficient per-object thread-local storage implementation.

use std::thread;
use std::sync::Arc;
use std::cell::RefCell;
use per_thread_object::ThreadLocal;

fn default() -> RefCell<u32> {
    RefCell::new(0x0)
}

let tl: Arc<ThreadLocal<RefCell<u32>>> = Arc::new(ThreadLocal::new());
let tl2 = tl.clone();

thread::spawn(move || {
    per_thread_object::stack_token!(token);

    *tl2.get_or_init(token, default).borrow_mut() += 1;
    let val = *tl2.get(token).unwrap().borrow();
    assert_eq!(0x1, val);
})
    .join()
    .unwrap();

per_thread_object::stack_token!(token);

*tl.get_or_init(token, default).borrow_mut() += 2;
assert_eq!(0x2, *tl.get_or_init(token, default).borrow());

Macros

Structs

Per-object thread-local storage

Constants