Scope

Struct Scope 

Source
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>

Source

pub fn global() -> Scope<'static>

Returns the global scope.

§Examples
let _s = Scope::global();
Source

pub fn join<A, B, RA, RB>(&mut self, a: A, b: B) -> (RA, RB)
where A: FnOnce(&mut Scope<'_>) -> RA + Send, B: FnOnce(&mut Scope<'_>) -> RB + Send, RA: Send, RB: Send,

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]);
Source

pub fn join_with_heartbeat_every<const TIMES: u8, A, B, RA, RB>( &mut self, a: A, b: B, ) -> (RA, RB)
where A: FnOnce(&mut Scope<'_>) -> RA + Send, B: FnOnce(&mut Scope<'_>) -> RB + Send, RA: Send, RB: Send,

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§

Source§

impl<'s> Debug for Scope<'s>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.