Struct arccell::ArcCell [] [src]

pub struct ArcCell<T> { /* fields omitted */ }

A thread-safe, lock-free mutable reference.

Examples

Using ArcCell for atomic compare-and-swap functionality:

use arccell::ArcCell;
use std::sync::Arc;

let acell = ArcCell::new(Arc::new(1i32));

let mut old = acell.get();
let mut new = Arc::new(*old + 1);
loop {
    match acell.compare_exchange(old, new) {
        Ok(x) => {
            old = x;
            break;
        },
        Err(x) => {
            old = x;
            new = Arc::new(*old + 1);
        }
    }
}
assert_eq!(*old + 1, *acell.get());

Using ArcCell with Arc (remember, ArcCell by itself is not an Arc, it only refers to an Arc):

use arccell::ArcCell;
use std::sync::Arc;

let acell = ArcCell::new(Arc::new(1i32));

let arc = Arc::new(acell);

let other = arc.clone();

assert!(Arc::ptr_eq(&arc.get(), &other.get()));

assert_eq!(*other.get(), 1);

Note: For simple examples like this, it might be best to use one of the Atomic types.

Methods

impl<T> ArcCell<T>
[src]

[src]

Creates a new ArcCell initialized with the given Arc<T>.

[src]

[src]

[src]

[src]

[src]

[src]