1 #ifndef _THREAD_POOL_H_ 2 #define _THREAD_POOL_H_ 7 #include <condition_variable> 43 enum state {waiting, running, dying, dead};
49 std::unique_ptr<enum state[]>
states;
66 std::condition_variable
cv;
79 void wait_raise(std::unique_lock<std::mutex>& lk,
const std::size_t to_check);
const std::size_t threads
Number of threads in pool.
std::condition_variable cv
Condition variable through which to notify workers that jobs are available.
std::unique_ptr< enum state[]> states
State variables for each thread.
std::function< void(void *)> delegate_t
The type of the delegate function each thread will run.
std::size_t remain
Count of the number of workers still to complete their job packets.
void manifold(delegate_t delegate, void **params, std::size_t jobs)
Execute a function in each of the threads, passing each one its own paramater set.
~ThreadPool()
Destroy the thread pool.
std::mutex m
Mutex to control access to job packets.
void wait_raise(std::unique_lock< std::mutex > &lk, const std::size_t to_check)
Convenience function: waits for a lock then deals with any exceptions propagated from the threads...
A utility class to permit a single function to be run on multiple datasets concurrently.
void dispatcher(int id)
Dispatch jobs to the given delegate.
ThreadPool(std::size_t numThreads=0)
Construct a thread pool.
state
thread state descriptor
void ** params
Parameters for each thread, passed to the runJobs function.
delegate_t delegate
The work the workers are supposed to perform.
std::unique_ptr< std::thread[]> workers
Worker threads.
std::unique_ptr< std::exception_ptr[]> exceptions
exception_ptrs for each thread