-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (44 loc) · 1.23 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <thread>
#include <mutex>
#include <sstream>
#include "methods.h"
using namespace std;
// Worker threads used in the program
thread *threads;
/**
* Entry point of the program, you know the start point of the bug hunting :D
*
* @return 0 or noting, in better case ;)
*/
int main() {
// Optimize input, output performance
ios::sync_with_stdio(false);
// Get number of working threads
int supportedThreads = getSupportedThreads();
ostringstream message;
message << "Supported threads: " << supportedThreads;
log(message);
// Create working threads
threads = new thread[supportedThreads];
for (int i = 0; i < supportedThreads; i++) {
// launch thread
threads[i] = thread(launchThread);
}
/*
* There is some work in the background...
* Because it's a multi-thread program :)
*/
// waiting for end of the threads
// This point should never reached
for (int i = 0; i < supportedThreads; i++) {
threads[i].join();
message.clear();
message << "Thread # " << i << " joined.";
log(message);
}
message.clear();
message << "End of the program";
log(message);
delete[] threads;
return EXIT_FAILURE;
}