pub struct ThreadPool { /* private fields */ }
Expand description
A thread pool for running fork-join workloads.
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn with_config(config: Config) -> Self
pub fn with_config(config: Config) -> Self
Creates a new thread pool with config
.
§Examples
let _tp = ThreadPool::with_config(Config {
thread_count: Some(NonZero::new(1).unwrap()),
heartbeat_interval: Duration::from_micros(50),
});
Sourcepub fn set_global(self) -> Result<(), Self>
pub fn set_global(self) -> Result<(), Self>
Sets the global thread pool to this one.
The global thread pool can only be set once. Any subsequent call will return the thread pool back.
§Examples
ThreadPool::with_config(Config {
thread_count: Some(NonZero::new(1).unwrap()),
heartbeat_interval: Duration::from_micros(50),
})
.set_global()
.unwrap();
Sourcepub fn global() -> &'static ThreadPool
pub fn global() -> &'static ThreadPool
Returns the global thread pool.
§Examples
let mut s = ThreadPool::global().scope();
let mut vals = [0; 2];
let (left, right) = vals.split_at_mut(1);
s.join(|_| left[0] = 1, |_| right[0] = 1);
assert_eq!(vals, [1; 2]);
Sourcepub fn scope(&self) -> Scope<'_>
pub fn scope(&self) -> Scope<'_>
Returns a Scope
d object that you can run fork-join workloads on.
§Examples
let mut tp = ThreadPool::new();
let mut s = tp.scope();
let mut vals = [0; 2];
let (left, right) = vals.split_at_mut(1);
s.join(|_| left[0] = 1, |_| right[0] = 1);
assert_eq!(vals, [1; 2]);
Trait Implementations§
Source§impl Debug for ThreadPool
impl Debug for ThreadPool
Source§impl Default for ThreadPool
impl Default for ThreadPool
Auto Trait Implementations§
impl Freeze for ThreadPool
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
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
Mutably borrows from an owned value. Read more