Struct hytra::TrAdder[][src]

pub struct TrAdder<T: Copy + Zero + Add<T, Output = T> + Send>(_);

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

impl<T> Send for TrAdder<T>

impl<T> Sync for TrAdder<T> where
    T: Sync

impl<T> Unpin for TrAdder<T> where
    T: Unpin

impl<T> UnwindSafe for TrAdder<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.