-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
32 lines (29 loc) · 795 Bytes
/
main.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
#include "thread_pool.hpp"
#include <iostream>
#include <chrono>
template<typename T>
void sync_print(T const& value){
static std::mutex pr;
std::unique_lock<std::mutex> lk{pr};
std::cout<<value<<std::endl;
}
int main(int argc, char** argv)
{
try{
thread_pool pool{4};
std::vector<std::future<int>> out;
auto it = std::chrono::high_resolution_clock::now();
for(int i =0; i < 1000000;++i)
{
out.push_back(pool.push([i](){
return i;
}));
}
out.back().wait();
auto ot = std::chrono::high_resolution_clock::now();
std::cout<< std::chrono::duration<double>(ot - it).count()<<std::endl;
}catch(std::exception& e){
sync_print(e.what());
}
return 0;
}