Struct crossbeam::thread::Scope[][src]

pub struct Scope<'env> { /* fields omitted */ }
Expand description

A scope for spawning threads.

Implementations

impl<'env> Scope<'env>[src]

pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where
    F: FnOnce(&Scope<'env>) -> T + Send + 'env,
    T: Send + 'env, 
[src]

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.

This will create a thread using default parameters of ScopedThreadBuilder, if you want to specify the stack size or the name of the thread, use this API instead.

Panics

Panics if the OS fails to create a thread; use ScopedThreadBuilder::spawn to recover from such errors.

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 self) -> ScopedThreadBuilder<'scope, 'env>[src]

Creates a builder that can configure a thread before spawning.

Examples

use crossbeam_utils::thread;

thread::scope(|s| {
    s.builder()
        .spawn(|_| println!("A child thread is running"))
        .unwrap();
}).unwrap();

Trait Implementations

impl<'_> Debug for Scope<'_>[src]

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

impl<'_> Sync for Scope<'_>[src]

Auto Trait Implementations

impl<'env> !RefUnwindSafe for Scope<'env>

impl<'env> Send for Scope<'env>

impl<'env> Unpin for Scope<'env>

impl<'env> !UnwindSafe for Scope<'env>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T[src]

pub const ALIGN: usize[src]

The alignment of pointer.

type Init = T

The type for initializers.

pub unsafe fn init(init: <T as Pointable>::Init) -> usize[src]

Initializes a with the given initializer. Read more

pub unsafe fn deref<'a>(ptr: usize) -> &'a T[src]

Dereferences the given pointer. Read more

pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T[src]

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)[src]

Drops the object pointed to by the given pointer. Read more

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.

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

Performs the conversion.

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.

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

Performs the conversion.