76 using R = std::invoke_result_t<F>;
77 auto task = std::make_shared<std::packaged_task<
R()>>(
83 if(_threadCount == 0) {
135 using Task = std::function<
void()>;
138 void spawnThreads(
int count);
140 mutable Mutex _mutex;
145 int _threadCount = 0;
146 int _activeCount = 0;
147 bool _shutdown =
false;
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
void pushToBack(const T &value)
Pushes an item onto the back of the list.
Definition list.h:455
RAII scoped locker for Mutex.
Definition mutex.h:41
Mutual exclusion lock wrapping std::mutex.
Definition mutex.h:33
General-purpose thread pool for submitting callable tasks.
Definition threadpool.h:44
int activeThreadCount() const
Returns the number of threads currently executing tasks.
int threadCount() const
Returns the current thread count.
Error waitForDone(unsigned int timeoutMs)
Blocks until all submitted tasks have completed or the timeout expires.
~ThreadPool()
Destructor. Signals shutdown and joins all worker threads.
void clear()
Removes all pending (not yet running) tasks from the queue.
void setThreadCount(int count)
Resizes the thread pool.
auto submit(F &&callable) -> Future< std::invoke_result_t< F > >
Submits a callable for asynchronous execution.
Definition threadpool.h:75
void waitForDone()
Blocks until all submitted tasks have completed.
ThreadPool(int threadCount=-1)
Constructs a ThreadPool with the given number of threads.
Condition variable wrapping std::condition_variable.
Definition waitcondition.h:26
void wakeOne()
Wakes one waiting thread.
Definition waitcondition.h:94
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19