Struct hytra::TrAdder [−][src]
The threaded add allows to increment and decrement an integer from multiple threads without
contention, which allows performance to scale well with the number of
thread/processors. TrAdder
can wrap any primitive integer type.
Overflow behavior. Overflow may occur if the sum of the increments in any subset of the threads overflows, even if the total leads to no overflow. Overflow semantic is the same as for primitive types (panic or wrapping).
See TrAcc
for a discussion of performance characteristics.
use hytra::TrAdder; let adder: TrAdder<i64> = TrAdder::new(); crossbeam_utils::thread::scope(|s| { for _ in 0..10 { s.spawn(|_| { for _ in 0..10 { adder.inc(1); } }); } }) .unwrap(); assert_eq!(adder.get(), 100);
Implementations
impl<T: Copy + Zero + Add<T, Output = T> + Send> TrAdder<T>
[src]
pub fn new() -> Self
[src]
Create a new TrAdder
initialized to 0.
pub fn inc(&self, x: T)
[src]
Increment the TrAdder
.
pub fn get(&self) -> T
[src]
Return the value of the TrAdder
.
Trait Implementations
impl<T: Debug + Copy + Zero + Add<T, Output = T> + Send> Debug for TrAdder<T>
[src]
impl<T: Copy + Zero + Add<T, Output = T> + Send> Default for TrAdder<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for TrAdder<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for TrAdder<T>
impl<T> Sync for TrAdder<T> where
T: Sync,
T: Sync,
impl<T> Unpin for TrAdder<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for TrAdder<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,