[−][src]Struct crossbeam_utils::thread::Scope
A scope for spawning threads.
Methods
impl<'env> Scope<'env>
[src]
pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where
F: FnOnce(&Scope<'env>) -> T,
F: Send + 'env,
T: Send + 'env,
[src]
F: FnOnce(&Scope<'env>) -> T,
F: Send + 'env,
T: Send + 'env,
Spawns a scoped thread.
This method is similar to the spawn
function in Rust's standard library. The difference
is that this thread is scoped, meaning it's guaranteed to terminate before the scope exits,
allowing it to reference variables outside the scope.
The scoped thread is passed a reference to this scope as an argument, which can be used for spawning nested threads.
The returned handle can be used to manually join the thread before the scope exits.
Examples
use crossbeam_utils::thread; thread::scope(|s| { let handle = s.spawn(|_| { println!("A child thread is running"); 42 }); // Join the thread and retrieve its result. let res = handle.join().unwrap(); assert_eq!(res, 42); }).unwrap();
pub fn builder<'scope>(&'scope self) -> ScopedThreadBuilder<'scope, 'env>
[src]
Creates a builder that can configure a thread before spawning.
Examples
use crossbeam_utils::thread; use std::thread::current; thread::scope(|s| { s.builder() .spawn(|_| println!("A child thread is running")) .unwrap(); }).unwrap();
Trait Implementations
Auto Trait Implementations
impl<'env> Send for Scope<'env>
impl<'env> Unpin for Scope<'env>
impl<'env> !UnwindSafe for Scope<'env>
impl<'env> !RefUnwindSafe for Scope<'env>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Wfn borrow_mut(&mut self) -> &mut T
[src]
ⓘImportant traits for &'_ mut W
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,