forked from bilash/threadpool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadpool_test.cpp
More file actions
45 lines (33 loc) · 792 Bytes
/
threadpool_test.cpp
File metadata and controls
45 lines (33 loc) · 792 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
35
36
37
38
39
40
41
42
43
44
45
#include "ThreadPool.h"
//#include "threadpool.h"
#include <iostream>
using namespace std;
const int MAX_TASKS = 4;
void hello(void* arg)
{
int* x = (int*) arg;
cout << "Hello " << *x << endl;
// cout << "\n";
}
int main(int argc, char* argv[])
{
ThreadPool tp(2);
int ret = tp.initialize_threadpool();
if (ret == -1) {
cerr << "Failed to initialize thread pool!" << endl;
return 0;
}
for (int i = 0; i < MAX_TASKS; i++) {
int* x = new int();
*x = i+1;
Task* t = new Task(&hello, (void*) x);
// cout << "Adding to pool, task " << i+1 << endl;
tp.add_task(t);
// cout << "Added to pool, task " << i+1 << endl;
}
sleep(2);
tp.destroy_threadpool();
// TODO: delete worker objects
cout << "Exiting app..." << endl;
return 0;
}