erebus

view liberebus/src/threadpool.h @ 24:4336acf8389d

implemented thread pool. not using it yet.
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 May 2014 06:56:44 +0300
parents
children c8a6fb04fefa
line source
1 #ifndef THREAD_POOL_H_
2 #define THREAD_POOL_H_
4 #include <list>
5 #include <functional>
6 #include <thread>
7 #include <mutex>
8 #include <condition_variable>
10 class ThreadPool {
11 private:
12 int num_threads;
13 std::thread *thread; // array of threads
15 std::list<std::function<void ()>> workq;
16 std::mutex workq_mutex;
17 std::condition_variable condvar;
19 bool quit;
21 void thread_func();
23 public:
24 ThreadPool(int num_threads = -1);
25 ~ThreadPool();
27 void add_work(std::function<void ()> func);
28 };
30 #endif // THREAD_POOL_H_