[−][src]Struct threader::thread_pool::ThreadPool
An executor which distributes tasks across multiple threads using a work-stealing
scheduler. Tasks can be spawned on it by calling the spawn
method on the ThreadPool
. Note that since this executor moves futures between different
threads, the future in question must be Send
.
Examples
use std::io; use threader::{ executor::Executor, thread_pool::ThreadPool, net::tcp::TcpStream, }; fn main() -> io::Result<()> { let mut pool = ThreadPool::new()?; let addr = "10.0.0.1:80".parse().unwrap(); pool.spawn(async move { let _stream = TcpStream::connect(&addr); }); pool.shutdown_on_idle(); Ok(()) }
Methods
impl ThreadPool
[src]
pub fn new() -> Result<ThreadPool>
[src]
Creates a new ThreadPool
instance with a number of threads
equal to the number of logical CPU cores in a given machine.
Returns any errors that may have occurred in creating the
thread pool.
Examples
use std::io; use threader::thread_pool::ThreadPool; fn main() -> io::Result<()> { let pool = ThreadPool::new()?; Ok(()) }
pub fn with_threads(count: usize) -> Result<ThreadPool>
[src]
Creates a new ThreadPool
instance with a number of threads
equal to count
. count
must not be zero, or this method
will panic. Like ThreadPool::new
, this method returns
any errors that occurred when creating the thread pool.
Panics
Panics if count
is equal to zero.
Examples
use std::io; use threader::thread_pool::ThreadPool; fn main() -> io::Result<()> { let pool = ThreadPool::with_threads(1)?; Ok(()) }
pub fn shutdown_on_idle(&mut self)
[src]
Shuts down the ThreadPool
when all worker threads are idle. This method
blocks the current thread until all of the worker threads have been joined.
pub fn shutdown_now(&mut self)
[src]
Shuts down the ThreadPool
immediately, sending a message to all worker
threads to shut down. This emethod blocks the current thread until all
worker threads have been joined, but this blocking shouldn't be noticeable.
Trait Implementations
impl<F> Executor<F> for ThreadPool where
F: Future<Output = ()> + Send + 'static,
[src]
F: Future<Output = ()> + Send + 'static,
impl Drop for ThreadPool
[src]
Auto Trait Implementations
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
impl !RefUnwindSafe for ThreadPool
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,