Struct crossbeam_arccell::ArcCell[][src]

pub struct ArcCell<T: 'static + Send + Sync> { /* fields omitted */ }

An updatable Arc.

Loads should always be constant-time, even in the face of both load and update contention.

Updates might take a long time, and the closure passed to it might run multiple times. This is because if the "old" value is updated before the closure finishes, the closure might overwrite up-to-date data and must be run again with said new data passed in. Additionally, memory reclamation of old ArcCell values is performed at this point.

Sets take much longer than loads as well, but they should be approximately constant-time as they don't need to be re-run if a different thread sets the ArcCell before it can finish.

Methods

impl<T: 'static + Send + Sync> ArcCell<T>
[src]

Create a new ArcCell pointing to data.

Example

let arc = ArcCell::new(vec![1,2,3,4]);

Update the ArcCell.

This is done by passing the current ArcCell value to a closure and setting the ArcCell to the closure's return value, provided no other threads have changed the ArcCell in the meantime.

If you don't care about any other threads setting the ArcCell during processing, use the set() method.

Example

let arc = ArcCell::new(vec![1,2,3,4]);
arc.update(|old| {
    let mut new = old.clone();
    new.push(5);
    new
})

Update the ArcCell in a fallible fashion.

Update the ArcCell without reclaiming any memory. Note that without calling reclaim() at some future point, this can cause a memory leak.

Update the ArcCell in a fallible fashion without reclaiming any memory. Note that without calling reclaim() at some future point, this can cause a memory leak.

Update the ArcCell, ignoring the current value.

Example

let arc = ArcCell::new(vec![1,2,3,4]);
arc.set(vec![9,8,7,6]);

Update the ArcCell, ignoring the current value and not reclaiming any memory. Note that without calling reclaim() at some future point, this can cause a memory leak.

Reclaim memory after calling update_no_reclaim(), update_fallible_no_reclaim() or set_no_reclaim().

Load the current value from the ArcCell.

This returns an ArcCell guard, rather than returning the internal value directly. In order to access the value explicitly, it must be dereferenced.

Example

let arc = ArcCell::new(vec![1,2,3,4]);
let guard = arc.load();
assert_eq!(*guard, vec![1,2,3,4]);

Warning

This method returns a guard that will pin the current thread, but won't directly hold on to a particular value. This means that even though load() has been called, it's not a guarantee that the data won't change between dereferences. As an example,

let arc = ArcCell::new(vec![1,2,3,4]);
let guard = arc.load();
assert_eq!(*guard, vec![1,2,3,4]);
arc.set(vec![9,8,7,6]);
assert_eq!(*guard, vec![9,8,7,6]);

Trait Implementations

impl<T: 'static + Send + Sync + Debug> Debug for ArcCell<T>
[src]

Formats the value using the given formatter. Read more

impl<T: 'static + Send + Sync + Display> Display for ArcCell<T>
[src]

Formats the value using the given formatter. Read more

impl<T: 'static + Send + Sync> Drop for ArcCell<T>
[src]

Executes the destructor for this type. Read more

impl<T: 'static + Send + Sync> Clone for ArcCell<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<T> Send for ArcCell<T>

impl<T> Sync for ArcCell<T>