Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef THREAD_POOL_H
- #define THREAD_POOL_H
- #include <vector>
- #include <thread>
- #include <queue>
- #include <mutex>
- #include <condition_variable>
- namespace concurrency {
- class thread_pool {
- protected:
- std::vector<std::thread> workers;
- int workers_count;
- int active_workers;
- bool stop;
- std::mutex mutex;
- std::condition_variable cond;
- typedef std::lock_guard<std::mutex> lockGuard;
- typedef std::unique_lock<std::mutex> uniqueLock;
- std::queue<std::function<void()>> queue;
- public:
- thread_pool(int);
- ~thread_pool();
- void start_workers();
- template<class F, class ...Args>
- void push(F&& f, Args&&... args);
- std::function<void()> pop();
- bool should_stop() {
- return stop;
- }
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement