Struct crossbeam_arccell::ArcCell [−][src]
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]
impl<T: 'static + Send + Sync> ArcCell<T>
pub fn new(data: T) -> ArcCell<T>
[src]
pub fn new(data: T) -> ArcCell<T>
pub fn update<F>(&self, f: F) where
F: Fn(&T) -> T,
[src]
pub fn update<F>(&self, f: F) where
F: Fn(&T) -> T,
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 })
pub fn update_fallible<F, E>(&self, f: F) -> Result<(), E> where
F: Fn(&T) -> Result<T, E>,
[src]
pub fn update_fallible<F, E>(&self, f: F) -> Result<(), E> where
F: Fn(&T) -> Result<T, E>,
Update the ArcCell in a fallible fashion.
pub fn update_no_reclaim<F>(&self, f: F) where
F: Fn(&T) -> T,
[src]
pub fn update_no_reclaim<F>(&self, f: F) where
F: Fn(&T) -> T,
Update the ArcCell without reclaiming any memory. Note that without calling reclaim() at some future point, this can cause a memory leak.
pub fn update_fallible_no_reclaim<F, E>(&self, f: F) -> Result<(), E> where
F: Fn(&T) -> Result<T, E>,
[src]
pub fn update_fallible_no_reclaim<F, E>(&self, f: F) -> Result<(), E> where
F: Fn(&T) -> Result<T, E>,
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.
pub fn set(&self, data: T)
[src]
pub fn set(&self, data: T)
Update the ArcCell, ignoring the current value.
Example
let arc = ArcCell::new(vec![1,2,3,4]); arc.set(vec![9,8,7,6]);
pub fn set_no_reclaim(&self, data: T)
[src]
pub fn set_no_reclaim(&self, data: T)
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.
pub fn reclaim(&self)
[src]
pub fn reclaim(&self)
Reclaim memory after calling update_no_reclaim()
, update_fallible_no_reclaim()
or set_no_reclaim()
.
pub fn load(&self) -> ArcCellGuard<T>
[src]
pub fn load(&self) -> ArcCellGuard<T>
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]
impl<T: 'static + Send + Sync + Debug> Debug for ArcCell<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: 'static + Send + Sync + Display> Display for ArcCell<T>
[src]
impl<T: 'static + Send + Sync + Display> Display for ArcCell<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: 'static + Send + Sync> Drop for ArcCell<T>
[src]
impl<T: 'static + Send + Sync> Drop for ArcCell<T>
impl<T: 'static + Send + Sync> Clone for ArcCell<T>
[src]
impl<T: 'static + Send + Sync> Clone for ArcCell<T>