-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (73 loc) · 1.72 KB
/
Copy pathmain.cpp
File metadata and controls
83 lines (73 loc) · 1.72 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#include <windows.h>
#elif __linux__
#elif TARGET_OS_MAC
#else
# error "Unknown compiler"
#endif
#include "threadpool.h"
class TPworker {
private:
int m_x{ 2 };
private:
inline int calsum(const int x, const int y = 152)
{
std::cout << "tdwork\n";
//::Sleep(8000);
//Sleep()
return x + y;
}
std::vector<int> calsub(const int& x, const int& y);
std::vector<int> vecsum(std::vector<int>& invec);
public:
int tpooltest()
{
ThreadPool pool(4);
std::vector< std::future<int> > results;
//pool.enqueue(this->calsum());
//auto xz = [this] {return this->calsum(); };
std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
auto rv0 = pool.addWorkFunc([this] { return this->calsum(1, 7); });
auto rv1 = pool.addWorkFunc([this] { return this->calsub(2, 12); });
auto rv2 = pool.addWorkFunc([this] { return this->calsum(3, 52); });
auto rv3 = pool.addWorkFunc([this] { return this->calsum(4, 91); });
auto rv4 = pool.addWorkFunc([this] { return this->calsub(4, 91); });
auto rv5 = pool.addWorkFunc([=, &vec] { return this->vecsum(vec); });
rv0.get();
rv1.get();
rv2.get();
auto flg01 = rv3.valid();
int a = rv3.get();
auto flg02 = rv3.valid();
auto b = rv4.get();
auto c = rv5.get();
std::cout << a << std::endl;
std::cout << b[0] << std::endl;
//int x = rv4.get();
int ds = 1;
return ds;
}
};
std::vector<int> TPworker::calsub(const int& x, const int& y)
{
std::vector<int> vec;
vec.push_back(x - y);
return vec;
}
std::vector<int> TPworker::vecsum(std::vector<int>& invec)
{
for(auto& it : invec)
{
it += m_x;
}
return invec;
}
int main()
{
TPworker tpw;
tpw.tpooltest();
return 0;
}