-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path_test_thread_pool.cpp
More file actions
86 lines (70 loc) · 1.44 KB
/
_test_thread_pool.cpp
File metadata and controls
86 lines (70 loc) · 1.44 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
84
85
86
/**
* @file test for thread_pool
* @brief
* @ref
* @author Yonhgwhan, Roh (fixbrain@gmail.com)
* @date 2020/07/19 created.
* @copyright All rights reserved by Yonghwan, Roh.
**/
#include "stdafx.h"
#include "_MyLib/src/thread_pool.h"
/**
* @brief thread_pool test
*/
void work()
{
log_info "tid = %u, running", GetCurrentThreadId() log_end;
};
struct worker
{
void operator()()
{
log_info "tid = %u, running", GetCurrentThreadId() log_end;
};
};
void more_work(int v)
{
log_info "tid = %u, running = %d", GetCurrentThreadId(), v log_end;
//getchar();
};
class RunClass
{
public:
bool CalledByThread(_In_ const char* msg)
{
log_info "tid=%u, msg=%s",
GetCurrentThreadId(),
msg
log_end;
return true;
}
};
bool test_thread_pool()
{
thread_pool pool(8);
pool.run_task(work); // Function pointer.
pool.run_task(worker()); // Callable object.
pool.run_task(boost::bind(more_work, 5)); // Callable object.
pool.run_task([]() // lambda
{
log_info "tid=%u", GetCurrentThreadId() log_end;
});
RunClass rc;
pool.run_task([&]()
{
if (true != rc.CalledByThread("test msg"))
{
log_err "rc.CalledByThread() failed." log_end;
}
else
{
log_info "rc.CalledByThread() succeeded." log_end;
}
});
// Wait until all tasks are done.
while (0 < pool.get_task_count())
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
}
return true;
}