pub struct Pool<X> { /* private fields */ }
Expand description
A handle to a lightweight thread pool. This is the primary type in the dynpool crate.
Pools spawn and close threads in LIFO (last spawned is first destroyed)
order. A worker (the context of execution bound to each thread) can be
restarted by issuing a Restart
decision, but the thread itself will only
shutdown if the scale is decreased.
Implementations
sourceimpl<X: System> Pool<X>
impl<X: System> Pool<X>
sourcepub fn start_bg(sys: X) -> Pool<X>
pub fn start_bg(sys: X) -> Pool<X>
Create a new manager which runs the given system in the background, starting a new thread for each worker.
sourcepub fn start_fg(sys: X) -> Result<(), PoolPanicedError>
pub fn start_fg(sys: X) -> Result<(), PoolPanicedError>
Create a new manager which runs the given system in the foreground, using the current thread to host the first worker. It will return when all workers have shutdown.
If a worker panics with unwind, then this function will return
Err(PoolPanicedError)
instantly, even if some workers are still
completing work. Due to limitations in std
, It is undefined behavior
for a worker to panic with abort.
sourcepub fn swap_system<Y: System>(&self, sys: Y) -> Pool<Y>
pub fn swap_system<Y: System>(&self, sys: Y) -> Pool<Y>
Gracefully change the system that this pool executes, and slowly replace all workers. This does not destroy the system or this handle. It simply tells threads to work on new tasks. A new pool handle is returned.
sourcepub fn system(&self) -> &X
pub fn system(&self) -> &X
Get a reference to the system associated with this pool handle. This system is not necessarily receiving work, since a different system may have been swapped onto the pool.
sourcepub fn thread_count(&self) -> usize
pub fn thread_count(&self) -> usize
Number of running threads. Note that since threads can spawn and close
at any time as a result of queries to System::scale
, this count may
not be correct.
sourcepub fn has_paniced(&self) -> bool
pub fn has_paniced(&self) -> bool
Has a worker in this pool paniced with unwind?
sourcepub fn join(self) -> Result<(), PoolPanicedError>
pub fn join(self) -> Result<(), PoolPanicedError>
Block until all workers have shutdown.
If a worker panics with unwind, then this function will return
Err(PoolPanicedError)
instantly, even if some workers are still
completing work. Due to limitations in std
, It is undefined behavior
for a worker to panic with abort. In such a case, join
will likely
never return.