Class ThreadPool
Defined in File thread-pool.h
Class Documentation
-
class ThreadPool
Public Functions
-
ThreadPool(uint32_t threadCount = uint32_t(~0x0), VoidFunction initializer = nullptr)
Main constructor.
- Parameters
threadCount -- Initial thread count, no value means equal to logical CPUs
-
~ThreadPool()
-
uint32_t ThreadCount()
Get current workers count.
-
uint32_t ThreadCountWithState(Thread::ThreadState state)
Get current workers count with provided state.
-
void AddThreads(uint32_t threadCount, VoidFunction initializer = nullptr)
Add new workers to the thread pool, with optional thread initializer callback.
-
template<typename Fun, typename ...Args>
inline auto SubmitJob(Fun &&function, Args&&... args) -> std::future<decltype(function(args...))> Submits provided function to the task queue for execution by workers.
- Returns
Future object representing task status
-
template<typename Fun, typename ...Args>
inline auto SubmitOptionalJob(Fun &&function, Args&&... args) -> std::future<decltype(function(args...))>
-
void WaitTillFinished()
Waits synchronously till all jobs submitted until now are finished.
-
template<typename Fun, typename ...Args>
inline auto RunWhenFinished(Fun &&function, Args&&... args) -> std::future<decltype(function(args...))> Run this code when all jobs submitted until now are finished.
-
void Shutdown()
Wait for running threads to finish their work and then shut down cleanly.
-
void CancelOptionalJobs()
Cancels submitted jobs that are marked as optional and are not in execution yet.
-
ThreadPool(uint32_t threadCount = uint32_t(~0x0), VoidFunction initializer = nullptr)