pub struct ThreadPool<Q: JobQueue = FifoQueue> { /* private fields */ }Expand description
OS thread pool for spawning computation tasks.
The pool enforces a hard limit on the number of threads. If all threads are
busy and the limit is reached, the job execution will be queued until a thread
becomes available. Idle threads are kept for idle_timeout to be potentially
reused for new tasks. All threads in the pool are spawned under round-robin
realtime policy (SCHED_RR) with a configured priority. Realtime threads
always take precedence over threads using normal policy (SCHED_OTHER),
so priority applies only among other realtime threads.
Workers are plain OS threads — they do not participate in rayon’s
work-stealing scheduler. This is important when spawned tasks may trigger
rayon-based parallel work internally (e.g. wasmtime’s parallel compilation):
since the workers are not rayon threads, nested rayon::join() calls fall
through to the global rayon pool instead of the worker’s pool, avoiding
deadlocks from recursive work-stealing.
Implementations§
Source§impl ThreadPool<FifoQueue>
impl ThreadPool<FifoQueue>
Source§impl<Q: JobQueue> ThreadPool<Q>
impl<Q: JobQueue> ThreadPool<Q>
Sourcepub fn spawn_boxed(&self, job: Job)
pub fn spawn_boxed(&self, job: Job)
Spawn a new task to be run on the pool. It will re-use existing idle threads if possible, or spawn a new thread (up to the configured limit). If at the thread limit and no idle threads are available, the job will be queued until a thread becomes available. The caller thread is never blocked.
Trait Implementations§
Source§impl<Q: JobQueue> AsyncComputationSpawner for ThreadPool<Q>
impl<Q: JobQueue> AsyncComputationSpawner for ThreadPool<Q>
Source§impl<Q: JobQueue> Debug for ThreadPool<Q>
impl<Q: JobQueue> Debug for ThreadPool<Q>
Source§impl<Q: JobQueue> Drop for ThreadPool<Q>
impl<Q: JobQueue> Drop for ThreadPool<Q>
Auto Trait Implementations§
impl<Q = FifoQueue> !RefUnwindSafe for ThreadPool<Q>
impl<Q = FifoQueue> !UnwindSafe for ThreadPool<Q>
impl<Q> Forget for ThreadPool<Q>
impl<Q> Freeze for ThreadPool<Q>
impl<Q> Move for ThreadPool<Q>
impl<Q> Send for ThreadPool<Q>
impl<Q> Sync for ThreadPool<Q>
impl<Q> Unpin for ThreadPool<Q>
impl<Q> UnsafeUnpin for ThreadPool<Q>where
Arc<ThreadPoolState<Q>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> AsyncComputationSpawnerExt for Twhere
T: AsyncComputationSpawner,
impl<T> AsyncComputationSpawnerExt for Twhere
T: AsyncComputationSpawner,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
impl<A, B> IntoMultiSender<B> for Awhere
B: MultiSenderFrom<A>,
fn as_multi_sender(self: &Arc<A>) -> B
fn into_multi_sender(self) -> B
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request