Struct jobsteal::Pool
[−]
[src]
pub struct Pool { /* fields omitted */ }
The work pool manages worker threads in a work-stealing fork-join thread pool.
You can submit jobs to the pool directly using Pool::submit
. This has similar
semantics to the standard library thread::spawn
, in that the work provided must
fully own its data.
Pool
also provides a facility for spawning scoped jobs via the "scope" function.
Methods
impl Pool
[src]
fn scope<'pool, 'new, F, R>(&'pool mut self, f: F) -> R where
F: 'new + FnOnce(&Spawner<'pool, 'new>) -> R,
R: 'new,
F: 'new + FnOnce(&Spawner<'pool, 'new>) -> R,
R: 'new,
Create a new spawning scope for submitting jobs.
This is shorthand for my_pool.spawner().scope(|scope| ...)
.
Any jobs submitted in this scope will be completed by the end of this function call. See Spawner::scope for a more detailed description.
fn recurse<'a, F>(&'a mut self, f: F) where
F: 'static + Send + FnOnce(&Spawner<'a, 'static>),
F: 'static + Send + FnOnce(&Spawner<'a, 'static>),
Execute a job which strictly owns its contents and is to be given access to the thread pool.
The execution of this function may be deferred beyond this function call,
to as far as either the next call to synchronize
or the pool's destructor.
This is shorthand for my_pool.spawner().recurse(my_job);
Safety
In the general case, it is safe to submit jobs which only strictly outlive the pool. However, there is always the chance that the pool could be leaked, violating the invariant that the job is completed while its data is still alive.
fn submit<'a, F>(&'a mut self, f: F) where
F: 'static + Send + FnOnce(),
F: 'static + Send + FnOnce(),
Execute a job which strictly owns its contents.
The execution of this function may be deferred beyond this function call,
to as far as either the next call to synchronize
or the pool's destructor.
This is shorthand for my_pool.spawner().submit(my_job);
Safety
In the general case, it is safe to submit jobs which only strictly outlive the pool. However, there is always the chance that the pool could be leaked, violating the invariant that the job is completed while its data is still alive.
fn spawner<'a>(&'a mut self) -> Spawner<'a, 'static>
Get the pool's spawner.
This will initally only accept jobs which outive 'static,
but the scope can be focused further.
See the Spawner
documentation for more information.