pub struct Pool<'p> { /* private fields */ }Expand description
A wrapper around a host’s borrowed, owned or shared Rayon pool.
tcontract never creates threads beyond this pool. Its size is fixed at construction (Rayon pools cannot resize). The embedded mutex serializes SPMD broadcasts through this wrapper. Hosts sharing a raw pool must retain one wrapper and serialize potentially conflicting numerical work, rather than constructing independent wrappers with separate SPMD mutexes.
§Examples
let tp = rayon::ThreadPoolBuilder::new().num_threads(3).build().unwrap();
let pool = tcontract_exec::Pool::borrow(&tp);
assert_eq!(pool.size(), 3);
assert_eq!(pool.stats().entries, 0);Implementations§
Source§impl<'p> Pool<'p>
impl<'p> Pool<'p>
Sourcepub fn borrow(pool: &'p ThreadPool) -> Self
pub fn borrow(pool: &'p ThreadPool) -> Self
Borrow a host pool.
Sourcepub fn workspace(&self) -> &ArenaProvider
pub fn workspace(&self) -> &ArenaProvider
The storage this pool lends to every operation that runs on it.
Borrowed, not copied: one pool is one owner, and a driver that is given this provider returns its team sets to it on drop.
Sourcepub fn trim_workspace(&self)
pub fn trim_workspace(&self)
Release the pool’s idle workspace storage. Live leases and borrowed worker buffers survive; a worker parked on this pool keeps its slot until it is idle again.
Sourcepub fn rayon_pool(&self) -> &ThreadPool
pub fn rayon_pool(&self) -> &ThreadPool
The raw Rayon pool this wrapper wraps.
For a provider that takes a rayon::ThreadPool directly (faer through
tlinalg, LAPACK) and must run on the host’s pool rather than a second
one. The wrapper’s retained workspace and its SPMD gate stay with the
wrapper: a provider that takes the bare pool does not share them, so a
host that mixes such a provider with this stack keeps one pool but two
workspace owners.
Sourcepub fn into_owned(self) -> Option<ThreadPool>
pub fn into_owned(self) -> Option<ThreadPool>
Give back an owned pool (None for a borrowed or shared one), for example
so a C host can drop it and join its workers. A shared wrapper releases
only its Arc reference; other owners keep the raw pool alive.
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Zero the counters.
Source§impl Pool<'static>
impl Pool<'static>
Share the host’s existing Rayon pool without creating another worker team.
Retain this wrapper across calls and share it (for example through an
Arc<Pool<'static>>) across host clones to reuse workspace and SPMD
serialization. Other numerical libraries may borrow the host’s original
raw pool, but their work must obey the host’s same resource-loan protocol.
§Examples
use std::sync::Arc;
let raw = Arc::new(rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap());
let pool = tcontract_exec::Pool::shared(Arc::clone(&raw));
assert_eq!(pool.size(), raw.current_num_threads());Sourcepub fn owned(pool: ThreadPool) -> Self
pub fn owned(pool: ThreadPool) -> Self
Take ownership of a pool, for hosts without one of their own (the C
ABI’s tcontract_tapp_executor_create_rayon). Rust hosts normally Pool::borrow.
§Examples
let tp = rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap();
let pool = tcontract_exec::Pool::owned(tp);
assert_eq!(pool.size(), 2);Trait Implementations§
Auto Trait Implementations§
impl<'p> !Freeze for Pool<'p>
impl<'p> !RefUnwindSafe for Pool<'p>
impl<'p> !UnwindSafe for Pool<'p>
impl<'p> Send for Pool<'p>
impl<'p> Sync for Pool<'p>
impl<'p> Unpin for Pool<'p>
impl<'p> UnsafeUnpin for Pool<'p>
Blanket Implementations§
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more