-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.cpp
106 lines (89 loc) · 1.96 KB
/
test.cpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "thread_pool.hpp"
#include <vector>
#include <iostream>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
using namespace std;
static void core_dump(int sigid)
{
kill(getpid(), SIGSEGV);
}
const int num_threads = 8;
void func_void_void(){
cout << "void" << endl;
}
void test_void_void(){
thread_pool p(num_threads);
vector<future<void>> f;
for(int i = 10000000;i < 20000000;i++)
f.emplace_back(p.async(func_void_void));
for(auto i = f.begin();i != f.end();i++)
i->get();
}
void func_void_int(int n){
bool prime = true;
if(n < 2)
prime = false;
for(int i = 2;i < n;i++)
if(n % i == 0)
prime = false;
cout << n << ": " << (prime ? "Prime" : "Composite") << endl;
}
void test_void_int(){
thread_pool p(num_threads);
vector<future<void>> f;
for(int i = 10000000;i < 20000000;i++)
f.emplace_back(p.async(func_void_int, i));
for(auto i = f.begin();i != f.end();i++)
i->get();
}
int func_int_void(){
return 42;
}
void test_int_void(){
thread_pool p(num_threads);
vector<future<int>> f;
for(int i = 100000;i < 1000000;i++)
f.emplace_back(p.async(func_int_void));
for(auto i = f.begin();i != f.end();i++)
cout << i->get() << endl;
}
bool func_bool_int(int n){
if(n < 2)
return false;
for(int i = 2;i < n;i++)
if(n % i == 0)
return false;
return true;
}
void test_bool_int(){
thread_pool p(num_threads);
vector<future<bool>> f;
int n = 100000;
int max = 10 * n;
for(int i = n;i < max;i++)
f.emplace_back(p.async(func_bool_int, i));
for(auto i = f.begin();i != f.end();i++, n++)
cout << n << ": " << i->get() << endl;
}
int func_int_int_int(int a, int b) {
return a * b;
}
void test_void_int_int() {
thread_pool p(num_threads);
vector<future<int>> f;
for(int i = 1;i < 100;i++) {
for(int j = 1;j < 100;j++) {
f.emplace_back(p.async(func_int_int_int, i, j));
}
}
for(auto i = f.begin();i != f.end();i++)
i->get();
}
int main(){
//signal(SIGINT, core_dump);
test_bool_int();
test_void_void();
return 0;
}