[−][src]Module swym::tcell
The core transactional memory primitive tcell::TCell
.
Examples
Creating a TCell
using new
:
use swym::tcell::TCell; let x = TCell::new(String::from("abcdefghijklmnopqrstuvwxyz")); static X: TCell<usize> = TCell::new(42);
Extracting values out of a TCell
using borrow
:
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("abcdefghijklmnopqrstuvwxyz")); thread_key::get().rw(|tx| { let string = x.borrow(tx, Default::default())?; assert_eq!(&*string, "abcdefghijklmnopqrstuvwxyz"); Ok(()) });
Modifying TCell
using set
:
use swym::{tcell::TCell, thread_key}; let x = TCell::new(String::from("abcdefghijklmnopqrstuvwxyz")); thread_key::get().rw(|tx| { x.set(tx, "hello".to_owned())?; Ok(()) }); assert_eq!(x.into_inner(), "hello");
Structs
Ref | A snapshot of a |
TCell | A transactional memory location. |
View | A view of a |