-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (58 loc) · 1.11 KB
/
main.cpp
File metadata and controls
67 lines (58 loc) · 1.11 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
#include <unistd.h>
#include <iostream>
#include "include/threadpool.h"
class TestTask : public Practice::Task {
public:
TestTask() {}
~TestTask() {}
virtual void run();
};
class TestTaskB : public Practice::Task {
public:
TestTaskB() {}
~TestTaskB() {}
virtual void run();
};
class TestTaskC : public Practice::Task {
public:
TestTaskC() {}
~TestTaskC() {}
virtual void run();
};
void TestTask::run() {
int i = 0;
for (int i = 0; i < 20; i++) {
std::cout << i << '\n';
sleep(0.2);
}
}
void TestTaskB::run() {
int i = 0;
for (int i = 20; i < 40; i++) {
std::cout << i << '\n';
sleep(0.2);
}
}
void TestTaskC::run() {
int i = 0;
for (int i = 40; i < 60; i++) {
std::cout << i << '\n';
sleep(0.2);
}
}
int main(int, char **) {
std::cout << "Hello, world!\n";
Practice::ThreadPool *pool = new Practice::ThreadPool(2,2);
TestTask *t = new TestTask();
TestTaskB *tb = new TestTaskB();
TestTaskC *tc = new TestTaskC();
pool->addTask(t);
pool->addTask(tb);
pool->addTask(tc);
sleep(10);
delete t;
delete tb;
delete tc;
delete pool;
return 0;
}