Enum scheduler::SchedulerScope
source · pub enum SchedulerScope<'sched, 'pool, 'scope, HostType: Host> {
ThreadPerHost(SchedulerScope<'pool, 'scope, HostType>),
ThreadPerCore(SchedulerScope<'sched, 'pool, 'scope, HostType>),
}
Expand description
A scope for any task run on the scheduler.
Variants§
ThreadPerHost(SchedulerScope<'pool, 'scope, HostType>)
ThreadPerCore(SchedulerScope<'sched, 'pool, 'scope, HostType>)
Implementations§
source§impl<'sched, 'pool, 'scope, HostType: Host> SchedulerScope<'sched, 'pool, 'scope, HostType>
impl<'sched, 'pool, 'scope, HostType: Host> SchedulerScope<'sched, 'pool, 'scope, HostType>
sourcepub fn run(self, f: impl Fn(usize) + Sync + Send + 'scope)
pub fn run(self, f: impl Fn(usize) + Sync + Send + 'scope)
Run the closure on all threads. The closure is given an index of the currently running thread.
sourcepub fn run_with_hosts(
self,
f: impl Fn(usize, &mut HostIter<'_, '_, HostType>) + Send + Sync + 'scope,
)
pub fn run_with_hosts( self, f: impl Fn(usize, &mut HostIter<'_, '_, HostType>) + Send + Sync + 'scope, )
Run the closure on all threads. The closure is given an index of the currently running thread and a host iterator.
The closure must iterate over the provided HostIter
to completion (until next()
returns
None
), otherwise this may panic. The host iterator is not a real std::iter::Iterator
,
but rather a fake iterator that behaves like a streaming iterator.
sourcepub fn run_with_data<T>(
self,
data: &'scope [T],
f: impl Fn(usize, &mut HostIter<'_, '_, HostType>, &T) + Send + Sync + 'scope,
)where
T: Sync,
pub fn run_with_data<T>(
self,
data: &'scope [T],
f: impl Fn(usize, &mut HostIter<'_, '_, HostType>, &T) + Send + Sync + 'scope,
)where
T: Sync,
Run the closure on all threads. The closure is given an index of the currently running
thread, a host iterator, and an element of data
.
The closure must iterate over the provided HostIter
to completion (until next()
returns
None
), otherwise this may panic. The host iterator is not a real std::iter::Iterator
,
but rather a fake iterator that behaves like a streaming iterator.
Each call of the closure will be given an element of data
, and this element will not be
given to any other thread while this closure is running, which means you should not expect
any contention on this element if using interior mutability. The provided slice must
have a length of at least Scheduler::parallelism
. If the data needs to be initialized,
it should be initialized before calling this function and not at the beginning of the
closure. The element may be given to multiple threads, but never two threads at the same
time.