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 super::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, ThreadPoolBuildError>

Creates a fixed thread pool with pool_size prestarted workers.

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

A fixed thread pool.

§Errors

Returns ThreadPoolBuildError 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.

Trait Implementations§

Source§

impl Drop for FixedThreadPool

Source§

fn drop(&mut self)

Requests graceful shutdown when the pool handle is dropped.

Source§

impl ExecutorService for FixedThreadPool

Source§

fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::Handle<R, E>, RejectedExecution>
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 RejectedExecution::Shutdown after shutdown or RejectedExecution::Saturated when a bounded queue is full.

Source§

fn shutdown(&self)

Stops accepting new work and drains accepted queued tasks.

Source§

fn shutdown_now(&self) -> ShutdownReport

Stops accepting work and cancels queued tasks.

§Returns

A count-based shutdown report.

Source§

fn is_shutdown(&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 await_termination(&self) -> Self::Termination<'_>

Waits until this fixed pool has terminated.

§Returns

A future that blocks the polling thread until termination.

Source§

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

Handle returned for an accepted task.
Source§

type Termination<'a> = Pin<Box<dyn Future<Output = ()> + Send + 'a>> where Self: 'a

Future returned when waiting for service termination.
Source§

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

Submits a runnable task to this service. 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> 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.