Struct solana_ledger::sigverify_shreds::SIGVERIFY_THREAD_POOL [−][src]
Methods from Deref<Target = ThreadPool>
pub fn install<OP, R>(&self, op: OP) -> R where
R: Send,
OP: FnOnce() -> R + Send,
[src]
R: Send,
OP: FnOnce() -> R + Send,
Executes op
within the threadpool. Any attempts to use
join
, scope
, or parallel iterators will then operate
within that threadpool.
Warning: thread-local data
Because op
is executing within the Rayon thread-pool,
thread-local data from the current thread will not be
accessible.
Panics
If op
should panic, that panic will be propagated.
Using install()
fn main() { let pool = rayon::ThreadPoolBuilder::new().num_threads(8).build().unwrap(); let n = pool.install(|| fib(20)); println!("{}", n); } fn fib(n: usize) -> usize { if n == 0 || n == 1 { return n; } let (a, b) = rayon::join(|| fib(n - 1), || fib(n - 2)); // runs inside of `pool` return a + b; }
pub fn current_num_threads(&self) -> usize
[src]
Returns the (current) number of threads in the thread pool.
Future compatibility note
Note that unless this thread-pool was created with a
ThreadPoolBuilder
that specifies the number of threads,
then this number may vary over time in future versions (see the
num_threads()
method for details).
pub fn current_thread_index(&self) -> Option<usize>
[src]
If called from a Rayon worker thread in this thread-pool,
returns the index of that thread; if not called from a Rayon
thread, or called from a Rayon thread that belongs to a
different thread-pool, returns None
.
The index for a given thread will not change over the thread’s lifetime. However, multiple threads may share the same index if they are in distinct thread-pools.
Future compatibility note
Currently, every thread-pool (including the global
thread-pool) has a fixed number of threads, but this may
change in future Rayon versions (see the num_threads()
method
for details). In that case, the index for a
thread would not change during its lifetime, but thread
indices may wind up being reused if threads are terminated and
restarted.
pub fn current_thread_has_pending_tasks(&self) -> Option<bool>
[src]
Returns true if the current worker thread currently has “local tasks” pending. This can be useful as part of a heuristic for deciding whether to spawn a new task or execute code on the current thread, particularly in breadth-first schedulers. However, keep in mind that this is an inherently racy check, as other worker threads may be actively “stealing” tasks from our local deque.
Background: Rayon’s uses a work-stealing scheduler. The
key idea is that each thread has its own deque of
tasks. Whenever a new task is spawned – whether through
join()
, Scope::spawn()
, or some other means – that new
task is pushed onto the thread’s local deque. Worker threads
have a preference for executing their own tasks; if however
they run out of tasks, they will go try to “steal” tasks from
other threads. This function therefore has an inherent race
with other active worker threads, which may be removing items
from the local deque.
pub fn join<A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB) where
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
RA: Send,
RB: Send,
[src]
A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
RA: Send,
RB: Send,
Execute oper_a
and oper_b
in the thread-pool and return
the results. Equivalent to self.install(|| join(oper_a, oper_b))
.
pub fn scope<'scope, OP, R>(&self, op: OP) -> R where
R: Send,
OP: FnOnce(&Scope<'scope>) -> R + Send,
[src]
R: Send,
OP: FnOnce(&Scope<'scope>) -> R + Send,
Creates a scope that executes within this thread-pool.
Equivalent to self.install(|| scope(...))
.
See also: the scope()
function.
pub fn scope_fifo<'scope, OP, R>(&self, op: OP) -> R where
R: Send,
OP: FnOnce(&ScopeFifo<'scope>) -> R + Send,
[src]
R: Send,
OP: FnOnce(&ScopeFifo<'scope>) -> R + Send,
Creates a scope that executes within this thread-pool.
Spawns from the same thread are prioritized in relative FIFO order.
Equivalent to self.install(|| scope_fifo(...))
.
See also: the scope_fifo()
function.
pub fn spawn<OP>(&self, op: OP) where
OP: FnOnce() + Send + 'static,
[src]
OP: FnOnce() + Send + 'static,
Spawns an asynchronous task in this thread-pool. This task will
run in the implicit, global scope, which means that it may outlast
the current stack frame – therefore, it cannot capture any references
onto the stack (you will likely need a move
closure).
See also: the spawn()
function defined on scopes.
pub fn spawn_fifo<OP>(&self, op: OP) where
OP: FnOnce() + Send + 'static,
[src]
OP: FnOnce() + Send + 'static,
Spawns an asynchronous task in this thread-pool. This task will
run in the implicit, global scope, which means that it may outlast
the current stack frame – therefore, it cannot capture any references
onto the stack (you will likely need a move
closure).
See also: the spawn_fifo()
function defined on scopes.
Trait Implementations
impl Deref for SIGVERIFY_THREAD_POOL
[src]
impl LazyStatic for SIGVERIFY_THREAD_POOL
[src]
fn initialize(lazy: &Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for SIGVERIFY_THREAD_POOL
impl Send for SIGVERIFY_THREAD_POOL
impl Sync for SIGVERIFY_THREAD_POOL
impl Unpin for SIGVERIFY_THREAD_POOL
impl UnwindSafe for SIGVERIFY_THREAD_POOL
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoRequest<T> for T
[src]
pub fn into_request(self) -> Request<T>
[src]
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
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.
pub 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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,
impl<T> WithSubscriber for T
[src]
pub fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,