Struct bp3d_threads::ThreadPool[][src]

pub struct ThreadPool<'env, Manager: ThreadManager<'env>, T: Send + 'static> { /* fields omitted */ }
Expand description

Core thread pool.

Implementations

Creates a new thread pool

Arguments
  • n_threads: maximum number of threads allowed to run at the same time.

returns: ThreadPool<T, Manager>

Examples
use bp3d_threads::UnscopedThreadManager;
use bp3d_threads::ThreadPool;
let _: ThreadPool<UnscopedThreadManager, ()> = ThreadPool::new(4);

Schedule a new task to run.

Returns true if the task was successfully scheduled, false otherwise.

The task execution order is not guaranteed, however the task index is guaranteed to be the order of the call to dispatch.

If a task panics it will leave a dead thread in the corresponding slot until .join() is called.

Arguments
  • manager: the thread manager to spawn a new thread if needed.
  • f: the task function to execute.

returns: bool

Examples
use bp3d_threads::UnscopedThreadManager;
use bp3d_threads::ThreadPool;
let manager = UnscopedThreadManager::new();
let mut pool: ThreadPool<UnscopedThreadManager, ()> = ThreadPool::new(4);
pool.dispatch(&manager, |_| ());

Returns true if this thread pool is idle.

An idle thread pool does neither have running threads nor waiting tasks but may still have waiting results to poll.

Poll a result from this thread pool if any, returns None if no result is available.

Waits for all tasks to finish execution and stops all threads.

Use this to periodically clean-up the thread pool, if you know that some tasks may panic.

Errors

Returns an error if a thread did panic.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.