pub fn scope_with<'pool, 'scope, F, R>(pool: &'pool ThreadPool, f: F) -> R
where
    F: FnOnce(&Scope<'pool, 'scope>) -> R,
{
    let finished_mutex = Mutex::new(false);
    let mut finished_guard = unsafe {
        mem::transmute::<MutexGuard<'_, bool>, MutexGuard<'static, bool>>(finished_mutex.lock())
    };
    let scope = Scope {
        pool,
        _marker: PhantomData,
        state: ScopeState {
            finished_mutex: &finished_mutex as *const Mutex<bool>,
            finished_guard: &mut finished_guard as *mut MutexGuard<bool>,
            cvar: Condvar::new(),
            tokens_outstanding: AtomicUsize::new(1),
            workers_panicked: AtomicUsize::new(0),
        },
    };
    let x = f(&scope);
    scope.join_all();

    let workers_panicked = scope.state.workers_panicked.load(Ordering::Acquire);
    if workers_panicked > 0 {
        panic!("Worker thread panic count: {}", workers_panicked);
    }

    drop(scope);
    drop(finished_guard);
    x
}
/// Borrows a threadpool creating a `Scope` which can be used to execute non-`'static` closures which may borrow from the scope of `scope_with`.
///
/// This is allowable as `scope_with` will not return until closures executed using the `Scope` are complete.
///
/// Note: By default the closure provided to `scope_with` may return much earlier than the closures it executes. If this is not desired call `join_all()` to force it to wait.


By default the closure provided to `scope_with` may return much earlier than the closures it executes. If this is not desired call `join_all()` to force it to wait.
By default the closure provided to ` scope_with ` may return much earlier than the closures it executes . If this is not desired call ` join_all () ` to force it to wait .
pub fn scope_with<'pool, 'scope, F, R>(pool: &'pool ThreadPool, f: F) -> R
where
    F: FnOnce(&Scope<'pool, 'scope>) -> R,
{
    let finished_mutex = Mutex::new(false);
    let mut finished_guard = unsafe {
        mem::transmute::<MutexGuard<'_, bool>, MutexGuard<'static, bool>>(finished_mutex.lock())
    };
    let scope = Scope {
        pool,
        _marker: PhantomData,
        state: ScopeState {
            finished_mutex: &finished_mutex as *const Mutex<bool>,
            finished_guard: &mut finished_guard as *mut MutexGuard<bool>,
            cvar: Condvar::new(),
            tokens_outstanding: AtomicUsize::new(1),
            workers_panicked: AtomicUsize::new(0),
        },
    };
    let x = f(&scope);
    scope.join_all();
    let workers_panicked = scope.state.workers_panicked.load(Ordering::Acquire);
    if workers_panicked > 0 {
        panic!("Worker thread panic count: {}", workers_panicked);
    }
    drop(scope);
    drop(finished_guard);
    x
}
pub fn scope_with < ' pool , ' scope , F , R > ( pool : & ' pool ThreadPool , f : F ) -> R where F : FnOnce ( & Scope < ' pool , ' scope > ) -> R , { let finished_mutex = Mutex :: new ( false ) ; let mut finished_guard = unsafe { mem :: transmute :: < MutexGuard < ' _ , bool > , MutexGuard < ' static , bool > > ( finished_mutex . lock ( ) ) } ; let scope = Scope { pool , _marker : PhantomData , state : ScopeState { finished_mutex : & finished_mutex as * const Mutex < bool > , finished_guard : & mut finished_guard as * mut MutexGuard < bool > , cvar : Condvar :: new ( ) , tokens_outstanding : AtomicUsize :: new ( 1 ) , workers_panicked : AtomicUsize :: new ( 0 ) , } , } ; let x = f ( & scope ) ; scope . join_all ( ) ; let workers_panicked = scope . state . workers_panicked . load ( Ordering :: Acquire ) ; if workers_panicked > 0 { panic ! ( " " workers_panicked ) ; } drop ( scope ) ; drop ( finished_guard ) ; x }
Borrows a threadpool creating a `Scope` which can be used to execute non-`'static` closures which may borrow from the scope of `scope_with`.
Borrows a threadpool creating a ` Scope ` which can be used to execute non - ` ' static ` closures which may borrow from the scope of ` scope_with ` .
pool
&'pool ThreadPool
f
F
pool
&'pool ThreadPool
f
F