pub struct Scope<'s> { /* private fields */ }Expand description
A Scoped object that you can run fork-join workloads on.
§Examples
let mut tp = ThreadPool::new();
let mut s = tp.scope();
let mut vals = [0; 2];
let (left, right) = vals.split_at_mut(1);
s.join(|_| left[0] = 1, |_| right[0] = 1);
assert_eq!(vals, [1; 2]);Implementations§
Source§impl<'s> Scope<'s>
impl<'s> Scope<'s>
Sourcepub fn join<A, B, RA, RB>(&mut self, a: A, b: B) -> (RA, RB)
pub fn join<A, B, RA, RB>(&mut self, a: A, b: B) -> (RA, RB)
Runs a and b potentially in parallel on separate threads and
returns the results.
This variant skips checking for a heartbeat every 16 calls for improved performance.
§Examples
let mut vals = [0; 2];
let (left, right) = vals.split_at_mut(1);
Scope::global().join(|_| left[0] = 1, |_| right[0] = 1);
assert_eq!(vals, [1; 2]);Sourcepub fn join_with_heartbeat_every<const TIMES: u8, A, B, RA, RB>(
&mut self,
a: A,
b: B,
) -> (RA, RB)
pub fn join_with_heartbeat_every<const TIMES: u8, A, B, RA, RB>( &mut self, a: A, b: B, ) -> (RA, RB)
Runs a and b potentially in parallel on separate threads and
returns the results.
This variant skips checking for a heartbeat every TIMES - 1 calls for
improved performance.
§Examples
let mut vals = [0; 2];
let (left, right) = vals.split_at_mut(1);
// Skip checking 7/8 calls to join_with_heartbeat_every.
Scope::global().join_with_heartbeat_every::<8, _, _, _, _>(|_| left[0] = 1, |_| right[0] = 1);
assert_eq!(vals, [1; 2]);Trait Implementations§
Auto Trait Implementations§
impl<'s> Freeze for Scope<'s>
impl<'s> !RefUnwindSafe for Scope<'s>
impl<'s> !Send for Scope<'s>
impl<'s> !Sync for Scope<'s>
impl<'s> Unpin for Scope<'s>
impl<'s> !UnwindSafe for Scope<'s>
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