Crate crossbeam_stm[][src]

This library provides a Software Transactional Memory structure that can be used for sharing data among multiple threads in a way that is safe and can be loaded quickly.

For more information, look at the documentation for the Stm struct.

Example

use crossbeam_stm::Stm;

// Create a new STM pointer with a Vec of numbers
let stm = Stm::new(vec![1,2,3,4]);

// Read from the STM
{
    let data = stm.load();
    println!("Current STM: {:?}", data);
}

// Update the STM pointer to add a new number
stm.update(|old| {
    let mut new = old.clone();
    new.push(5);
    new
});

// Read the new data
{
    let data = stm.load();
    println!("Current STM: {:?}", data);
}

// Set the STM pointer
let data = vec![9,8,7,6];
stm.set(data);

// Read the new data, again
{
    let data = stm.load();
    println!("Current STM: {:?}", data);
}

Structs

Stm

A Software Transactional Memory pointer.

StmGuard

Structure that ensures any loaded data won't be freed by a future update.