Analytics Template Library
 All Classes Namespaces Functions Variables Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
atl::ThreadPool Class Reference

#include <ThreadPool.hpp>

Public Member Functions

 ThreadPool (int threads=std::thread::hardware_concurrency())
 
void Start (int threads=std::thread::hardware_concurrency())
 
size_t Size ()
 
void DoJob (std::function< void(void) > func)
 
void DoJob (std::function< void(void) > func, WaitVariable &wait)
 
template<class InputIt , typename Function >
void ForEach (InputIt first, const size_t &elements, const Function &function)
 
template<class InputIt , typename Function >
void ForEach (InputIt first, const size_t &elements, const Function &function, WaitVariable &wait)
 
void Wait (WaitVariable &wait)
 
 ThreadPool (int threads=std::thread::hardware_concurrency())
 
 ~ThreadPool ()
 
void Start (int threads=std::thread::hardware_concurrency())
 
size_t Size ()
 
void DoJob (std::function< void(void) > func)
 
void DoJob (std::function< void(void) > func, WaitVariable &wait)
 
template<class InputIt , typename Function >
void ForEach (InputIt first, const size_t &elements, const Function &function)
 
template<class InputIt , typename Function >
void ForEach (InputIt first, const size_t &elements, const Function &function, WaitVariable &wait)
 
void Wait (WaitVariable &wait)
 

Protected Member Functions

void threadEntry (int i)
 
void threadEntry (int i)
 

Protected Attributes

std::mutex lock_
 
std::condition_variable condVar_
 
bool shutdown_
 
bool started_
 
size_t thread_count
 
std::queue< std::function
< void(void) > > 
jobs_
 
std::vector< std::thread > threads_
 

Detailed Description

Thread pool.

Constructor & Destructor Documentation

atl::ThreadPool::ThreadPool ( int  threads = std::thread::hardware_concurrency())
inline

Constructor. Sets the number of threads in this thread pool.

Parameters
threads
atl::ThreadPool::~ThreadPool ( )
inline

Destructor. Shuts down all threads.

Member Function Documentation

void atl::ThreadPool::DoJob ( std::function< void(void) >  func)
inline

Do a job that doesn't require wait.

Parameters
func
void atl::ThreadPool::DoJob ( std::function< void(void) >  func,
WaitVariable wait 
)
inline

Do a job that requires wait. The wait variable is incremented.

Parameters
func
wait
template<class InputIt , typename Function >
void atl::ThreadPool::ForEach ( InputIt  first,
const size_t &  elements,
const Function &  function 
)
inline

For each job.

Parameters
first
elements
function
template<class InputIt , typename Function >
void atl::ThreadPool::ForEach ( InputIt  first,
const size_t &  elements,
const Function &  function,
WaitVariable wait 
)
inline

For each job with wait.

Parameters
first
elements
function
wait
size_t atl::ThreadPool::Size ( )
inline

Returns the number of threads in this thread pool.

Returns
void atl::ThreadPool::Wait ( WaitVariable wait)
inline

Wait for this wait variable to signal completion.

Parameters
wait

The documentation for this class was generated from the following file: