46#include <condition_variable>
64 explicit thread_pool(
unsigned int num_threads = std::thread::hardware_concurrency() * 4);
76 int init(
unsigned int num_threads = 0);
int init(unsigned int num_threads=0)
Initialise thread pool. Initialise the thread pool. Does nothing if called more than once.
std::condition_variable m_queue_cond
unsigned int pool_size() const
Get current pool size.
unsigned int m_num_threads
std::function< int(void)> FunctionPointer
Pointer to thread pool function.
void loop_function()
Start loop function.
std::vector< std::thread > m_thread_pool
std::queue< FunctionPointer > m_thread_queue
static void loop_function_starter(thread_pool &tp)
Start loop function.
void tear_down(bool silent=false)
Shut down the thread pool.
unsigned int m_cur_threads
bool schedule_thread(FunctionPointer &&func)
Schedule a new thread from pool.
virtual ~thread_pool()
Object destructor. Ends all threads and cleans up resources.
std::atomic_uint32_t m_threads_running
unsigned int current_queued()
Get number of currently queued threads.
thread_pool(unsigned int num_threads=std::thread::hardware_concurrency() *4)
Construct a thread_pool object.
std::atomic_bool m_queue_shutdown
unsigned int current_running() const
Get number of currently running threads.
std::unique_ptr< thread_pool > tp
Thread pool object.