-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
26 lines (25 loc) · 907 Bytes
/
main.cpp
File metadata and controls
26 lines (25 loc) · 907 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
#include <chrono>
#include <iostream>
#include "thread_pool.h"
int main() {
auto start = std::chrono::high_resolution_clock::now();
thread_pool::ThreadPool threadPool(8);
std::function<void()> const func1 = []() {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::cout << "func1 from other thread!\n";
};
std::function<void()> const func2 = []() {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "func2 from other thread!\n";
};
threadPool.add_task(func1);
threadPool.add_task(func2);
threadPool.wait_all();
auto finish = std::chrono::high_resolution_clock::now();
auto duration = finish - start;
std::cerr << "Program ended in "
<< std::chrono::duration_cast<std::chrono::milliseconds>(duration)
.count()
<< "ms\n";
return 0;
}