15 #ifndef IMPALA_UTIL_THREAD_POOL_H
16 #define IMPALA_UTIL_THREAD_POOL_H
20 #include <boost/thread/mutex.hpp>
21 #include <boost/bind/mem_fn.hpp>
35 typedef boost::function<void (int thread_id, const T& workitem)>
WorkFunction;
43 ThreadPool(
const std::string& group,
const std::string& thread_prefix,
44 uint32_t num_threads, uint32_t queue_size,
const WorkFunction& work_function)
48 for (
int i = 0; i < num_threads; ++i) {
49 std::stringstream threadname;
50 threadname << thread_prefix <<
"(" << i + 1 <<
":" << num_threads <<
")";
84 boost::lock_guard<boost::mutex> l(
lock_);
105 boost::unique_lock<boost::mutex> l(
lock_);
131 boost::unique_lock<boost::mutex> l(
lock_);
139 boost::lock_guard<boost::mutex> l(
lock_);
Status SetCgroup(const std::string &cgroup)
TODO: Consider allowing fragment IDs as category parameters.
ThreadGroup threads_
Collection of worker threads that process work from the queue.
void WorkerThread(int thread_id)
bool shutdown_
Set to true when threads should stop doing work and terminate.
bool Offer(const T &work)
BlockingQueue< T > work_queue_
boost::condition_variable empty_cv_
Signalled when the queue becomes empty.
bool IsShutdown()
Returns value of shutdown_ under a lock, forcing visibility to threads in the pool.
uint32_t GetQueueSize() const
ThreadPool(const std::string &group, const std::string &thread_prefix, uint32_t num_threads, uint32_t queue_size, const WorkFunction &work_function)
boost::function< void(int thread_id, const T &workitem)> WorkFunction
Status AddThread(Thread *thread)
boost::mutex lock_
Guards shutdown_ and empty_cv_.
WorkFunction work_function_
User-supplied method to call to process each work item.
Status AssignToCgroup(const std::string &cgroup)