Crate lock_free_static
source ·Expand description
Examples
Static variable
lock_free_static!{
static VAR: i32 = 123;
}
fn main() {
assert!(VAR.init());
assert_eq!(*VAR.get().unwrap(), 123);
}
Mutable static variable
lock_free_static!{
static mut VAR: i32 = 123;
}
fn main() {
assert!(VAR.init());
let mut guard = VAR.lock().unwrap();
assert_eq!(*guard, 123);
*guard = 321;
drop(guard);
assert_eq!(*VAR.lock().unwrap(), 321);
}
Macros
- Convenience macro for creating lock-free statics.
Structs
- Convenience wrapper for static initialization of cells.
- Lock-free mutex.
Mutex
lock guard.- Lock-free thread-safe cell which can be written to only once.
- Like
OnceCell
but with exclusive mutable access to its content.
Type Aliases
OnceMut
lock guard.