Struct lagoon::ThreadPool [−][src]
pub struct ThreadPool { /* fields omitted */ }
Expand description
A pool of threads that may be used to execute jobs.
Implementations
The default number of threads that will be used if the available concurrency of the environment cannot be determined automatically.
Returns a reference to the global ThreadPool
, instantiating as with ThreadPool::default
if it is not
already initialized.
This should be used when you don’t require any specific thread pool configuration to avoid multiple thread pools fighting for scheduler time.
Returns a reference to the global ThreadPool
, initializing it with the given ThreadPoolBuilder
if it
is not already initialized.
Do not use this function if you are writing a library. Use ThreadPool::global
instead so that the final
binary crate is the one to determine the thread pool configuration (the end developer likely knows more about
their specific threading requirements than you do and can use this information to optimise thread pool
performance and minimise resource contention).
If your application has specific pool requirements (for example, most games require thread pools to use N - 1
threads to ensure that at least one core is free at any given time to keep the main thread running smoothly
without stuttering) you should use this function as early as possible in the program’s execution (i.e: at the
top of the main
function) to avoid dependencies initializing it first.
Note additionally that the configuration you choose might interfere with dependencies that also use the global thread pool. Choose sensible, accomodating defaults where possible.
Begin building a new ThreadPool
.
Returns the number of threads in this pool.
Enqueue a function to be executed as a job when a thread is free to do so.
let pool = lagoon::ThreadPool::default(); for i in 0..10 { pool.run(move || println!("I am the {}th job!", i)); }
Enqueue a function to be executed as a job when a thread is free to do so, returning a handle that allows retrieval of the return value of the function.
Signal to threads (not jobs) that they should stop, then wait for them to finish processing jobs.
All outstanding jobs will be executed before this function returns.
Create a scope that allows the spawning of threads with safe access to the current scope.
This function will wait for all jobs created in the scope to finish before continuing. See Scope
for more
information about scoped jobs.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool