-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (49 loc) · 1.05 KB
/
main.cpp
File metadata and controls
58 lines (49 loc) · 1.05 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
#include "fastprogressbar.h"
#include <thread>
#include <chrono>
#include <vector>
using namespace std;
static void test_single_thread()
{
fastprogressbar bar;
bar.set_bar_style(0);
bar.set_niter(100);
for (int i = 0; i < 100; i++)
{
bar.update();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
static void test_multi_thread()
{
int nthreads = 10;
fastprogressbar bar;
bar.set_niter(1000);
bar.set_bar_style(1);
// create threads
vector<thread> threads;
for (int i = 0; i < nthreads; i++)
{
threads.emplace_back([&bar]() {
for (int i = 0; i < 100; i++)
{
bar.update();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
});
}
// join threads
for (auto& t : threads)
{
t.join();
}
}
int main()
{
cout << "single thread:" << endl;
test_single_thread();
cout << endl;
cout << "multi thread:" << endl;
test_multi_thread();
return 0;
}