Thread pool implementation.
More...
#include <AUI/Thread/AThreadPool.h>
|
| enum | Priority { PRIORITY_HIGHEST
, PRIORITY_MEDIUM
, PRIORITY_LOWEST
} |
| |
|
| | AThreadPool (size_t size) |
| | Initializes the thread pool with size of threads.
|
| |
|
| AThreadPool () |
| | Initializes the thread pool with max(std::thread::hardware_concurrency() - 1, 2) of threads or –aui-threadpool-size=SIZE passed to your application.
|
| |
|
size_t | getPendingTaskCount () |
| |
|
size_t | getTotalTaskCount () |
| |
|
void | run (const std::function< void()> &fun, Priority priority=PRIORITY_MEDIUM) |
| |
|
void | clear () |
| |
|
void | runLaterTasks () |
| |
|
void | setWorkersCount (std::size_t workersCount) |
| |
|
void | wakeUpAll () |
| |
|
const AVector< _< Worker > > & | workers () const |
| |
|
size_t | getTotalWorkerCount () const |
| |
|
size_t | getIdleWorkerCount () const |
| |
| template<typename Iterator, typename Functor> |
| auto | parallel (Iterator begin, Iterator end, Functor &&functor) |
| |
|
template<aui::invocable Callable> |
| auto | operator* (Callable fun) |
| |
|
|
static void | enqueue (const std::function< void()> &fun, Priority priority=PRIORITY_MEDIUM) |
| |
|
static AThreadPool & | global () |
| | Global thread pool created with the default constructor.
|
| |
|
|
typedef std::function< void()> | task |
| |
|
|
AVector< _< Worker > > | mWorkers |
| |
|
AQueue< task > | mQueueHighest |
| |
|
AQueue< task > | mQueueMedium |
| |
|
AQueue< task > | mQueueLowest |
| |
|
AQueue< task > | mQueueTryLater |
| |
|
std::mutex | mQueueLock |
| |
|
std::condition_variable | mCV |
| |
|
size_t | mIdleWorkers = 0 |
| |
- See also
- AThreadPool::global()
◆ AThreadPool()#
| AThreadPool::AThreadPool |
( |
size_t | size | ) |
|
- Parameters
-
| size | thread count to initialize. |
◆ parallel()#
template<typename Iterator, typename Functor>
| auto AThreadPool::parallel |
( |
Iterator | begin, |
|
|
Iterator | end, |
|
|
Functor && | functor ) |
Parallels work of some range, grouping tasks per thread (i.e. for 8 items on a 4-core processor each core will process 2 items)
- Parameters
-
| begin | range begin |
| end | range end |
| functor | a functor of the following signature: Result(Iterator begin, Iterator end)
|
- Returns
- future set per thread (i.e. for 8 items on a 4-core processor there will be 4 futures)
- Performance note
- When this function is used to write to the source data it would not be L1-cache friendly. Consider writing results to another location.