SPH
|
Thread pool capable of executing tasks concurrently. More...
#include <Pool.h>
Public Member Functions | |
ThreadPool (const Size numThreads=0, const Size granularity=1000) | |
Initialize thread pool given the number of threads to use. More... | |
~ThreadPool () | |
virtual SharedPtr< ITask > | submit (const Function< void()> &task) override |
Submits a task into the thread pool. More... | |
virtual Optional< Size > | getThreadIdx () const override |
Returns the index of this thread, or NOTHING if this thread was not invoked by the thread pool. More... | |
virtual Size | getThreadCnt () const override |
Returns the number of threads used by this thread pool. More... | |
virtual Size | getRecommendedGranularity () const override |
Returns a value of granularity that is expected to perform well with the current thread count. More... | |
void | waitForAll () |
Blocks until all submitted tasks has been finished. More... | |
Size | remainingTaskCnt () |
Returns the number of unfinished tasks. More... | |
void | setGranularity (const Size newGranularity) |
Modifies the default granularity of the thread pool. More... | |
Public Member Functions inherited from IScheduler | |
virtual void | parallelFor (const Size from, const Size to, const Size granularity, const Function< void(Size n1, Size n2)> &functor) |
Processes the given range concurrently. More... | |
Public Member Functions inherited from Polymorphic | |
virtual | ~Polymorphic () |
Static Public Member Functions | |
static SharedPtr< ThreadPool > | getGlobalInstance () |
Returns the global instance of the thread pool. More... | |
Friends | |
class | Task |
|
static |
|
overridevirtual |
Returns a value of granularity that is expected to perform well with the current thread count.
Implements IScheduler.
|
overridevirtual |
Returns the number of threads used by this thread pool.
Note that this number is constant during the lifetime of thread pool.
Implements IScheduler.
Returns the index of this thread, or NOTHING if this thread was not invoked by the thread pool.
The index is within [0, numThreads-1].
Implements IScheduler.
|
inline |
|
inline |
Submits a task into the thread pool.
The task will be executed asynchronously once tasks submitted before it are completed.
Implements IScheduler.
void ThreadPool::waitForAll | ( | ) |