pub struct TrAdder<T: Copy + Zero + Add<T, Output = T> + Send>(/* private fields */);Expand description
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§
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for TrAdder<T>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more