Class ThreadPool

Class Documentation

class aslam::ThreadPool

Public Functions

ThreadPool(const size_t numThreads)

Create a thread pool.


numThreads[in] The number of threads in the pool.

template<class Function, class ...Args>
std::future<typename std::result_of<Function(Args...)>::type> enqueueOrdered(const size_t exclusivity_group_id, Function &&function, Args&&... args)

Enqueue work for the thread pool.

Pass in a function and its arguments to enqueue work in the thread pool

  • function[in] A function pointer to be called by a thread.

  • exclusivity_group_id[in] All tasks belonging to the same group id are executed in series and the order is guaranteed. A group id of kGroupdIdNonExclusiveTask means there are no such guarantees.


A std::future that will return the result of calling function. If this function is called after the thread pool has been stopped, it will return an uninitialized future that will return future.valid() == false

template<class Function, class ...Args>
std::future<typename std::result_of<Function(Args...)>::type> enqueue(Function &&function, Args&&... args)

Same as method enqueueOrdered but the group id is set to -1 per default and all tasks are started in order but there is no guarantee on the result order.

inline void stop()

Stop the thread pool. This method is non-blocking.

size_t numQueuedTasks() const
void waitForEmptyQueue() const

This method blocks until the queue is empty.

size_t numActiveThreads() const

Public Static Attributes

static constexpr size_t kGroupdIdNonExclusiveTask = std::numeric_limits<size_t>::max()