-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadpool.h
More file actions
35 lines (32 loc) · 750 Bytes
/
threadpool.h
File metadata and controls
35 lines (32 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <mutex>
#include <condition_variable>
#include <unistd.h>
#include <map>
#include <algorithm>
#include <utility>
#include <thread>
#include <typeindex>
#include <queue>
class Taskmap {
public:
void insert_task(int priority, std::function<void()> func);
bool empty();
std::function<void()> pull_task();
private:
std::multimap<int, std::function<void()> > m;
std::mutex mut;
};
class Threadpool {
public:
Threadpool(int max_worker);
~Threadpool();
void end_pool();
template<class F, class... Args> void queue_task(int pri, F&& f, Args&&... args);
private:
std::mutex mut;
std::condition_variable cv;
std::deque<std::thread> thread_deque;
Taskmap tm;
bool quit;
};