Skip to main content

FixedThreadPool

Struct FixedThreadPool 

Source
pub struct FixedThreadPool { /* private fields */ }
Expand description

Fixed-size thread pool implementing ExecutorService.

FixedThreadPool prestarts a fixed number of worker threads and does not support runtime pool-size changes. Use crate::ThreadPool when dynamic core/maximum sizes or keep-alive policies are required.

Implementations§

Source§

impl FixedThreadPool

Source

pub fn new(pool_size: usize) -> Result<Self, ExecutorServiceBuilderError>

Creates a fixed thread pool with pool_size prestarted workers.

§Parameters
  • pool_size - Number of worker threads.
§Returns

A fixed thread pool.

§Errors

Returns ExecutorServiceBuilderError if the worker count is zero or a worker cannot be spawned.

Source

pub fn builder() -> FixedThreadPoolBuilder

Creates a fixed pool builder.

§Returns

Builder with CPU parallelism defaults.

Source

pub fn pool_size(&self) -> usize

Returns the fixed worker count.

§Returns

Number of workers in this pool.

Source

pub fn queued_count(&self) -> usize

Returns the queued task count.

§Returns

Number of accepted tasks waiting to run.

Source

pub fn running_count(&self) -> usize

Returns the running task count.

§Returns

Number of tasks currently held by workers.

Source

pub fn live_worker_count(&self) -> usize

Returns the live worker count.

§Returns

Number of worker loops that have not exited.

Source

pub fn stats(&self) -> ThreadPoolStats

Returns a point-in-time stats snapshot.

§Returns

Snapshot containing queue, worker, and lifecycle counters.

Source

pub fn join(&self)

Blocks until all accepted work has completed.

This is a join-style wait for quiescence: it does not request shutdown and does not wait for worker threads to exit. Concurrent submissions may extend the wait until those accepted jobs also drain.

Trait Implementations§

Source§

impl Default for FixedThreadPool

Source§

fn default() -> Self

Creates a fixed thread pool using FixedThreadPoolBuilder::default.

§Returns

A fixed thread pool with CPU parallelism defaults and prestarted workers.

§Panics

Panics when the default builder fails to spawn a worker thread.

Source§

impl Drop for FixedThreadPool

Source§

fn drop(&mut self)

Requests graceful shutdown when the pool handle is dropped.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl ExecutorService for FixedThreadPool

Source§

fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

Accepts a runnable and queues it for fixed pool workers.

Source§

fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::ResultHandle<R, E>, SubmissionError>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Accepts a callable and queues it for fixed pool workers.

§Parameters
  • task - Callable to execute on a fixed pool worker.
§Returns

A TaskHandle for the accepted task.

§Errors

Returns SubmissionError::Shutdown after shutdown or SubmissionError::Saturated when a bounded queue is full.

Source§

fn submit_tracked_callable<C, R, E>( &self, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Accepts a callable and queues it with a tracked handle.

§Parameters
  • task - Callable to execute on a fixed pool worker.
§Returns

A TrackedTask that reports task status and can observe completion, failure, or queued cancellation.

§Errors

Returns SubmissionError::Shutdown after shutdown or SubmissionError::Saturated when a bounded queue is full.

Source§

fn shutdown(&self)

Stops accepting new work and drains accepted queued tasks.

Source§

fn stop(&self) -> StopReport

Stops accepting work and cancels queued tasks.

§Returns

A count-based shutdown report.

Source§

fn lifecycle(&self) -> ExecutorServiceLifecycle

Returns the current lifecycle state.

Source§

fn is_not_running(&self) -> bool

Returns whether shutdown has been requested.

§Returns

true when this pool no longer accepts new work.

Source§

fn is_terminated(&self) -> bool

Returns whether this pool is fully terminated.

§Returns

true after shutdown and after all workers have exited.

Source§

fn wait_termination(&self)

Blocks until this fixed pool has terminated.

Source§

type ResultHandle<R, E> = TaskHandle<R, E> where R: Send + 'static, E: Send + 'static

Result handle returned for an accepted callable task.
Source§

type TrackedHandle<R, E> = TrackedTask<R, E> where R: Send + 'static, E: Send + 'static

Tracked handle returned for accepted tasks that expose status.
Source§

fn submit_tracked<T, E>( &self, task: T, ) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

Submits a runnable task and returns a tracked handle. Read more
Source§

fn is_running(&self) -> bool

Returns whether the service accepts new tasks. Read more
Source§

fn is_shutting_down(&self) -> bool

Returns whether graceful shutdown is in progress. Read more
Source§

fn is_stopping(&self) -> bool

Returns whether abrupt stop is in progress. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.