-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
35 lines (26 loc) · 903 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
33
34
35
#include <iostream>
#include <memory>
#include <thread>
#include <vector>
#include <controller.h>
#include <LoadBalancer.h>
using namespace std;
int main() {
const int NUM_THREADS = 5;
const int MAX_NUM = 100;
std::thread threads[NUM_THREADS];
Controller controllers[NUM_THREADS];
LoadBalancer loadBalancer;
vector<int> tasks_balance = loadBalancer.balance(NUM_THREADS, MAX_NUM);
for (int i=0; i<NUM_THREADS; i++) {
controllers[i] = Controller(std::make_shared<FileOutStream> (LoadBalancer::tmp_filename(i)),
std::make_shared<IntNumber> ());
std::thread t(&Controller::process_period, &controllers[i], tasks_balance[i*2], tasks_balance[i*2+1]);
threads[i] = std::move(t);
}
for(auto & thread : threads) {
thread.join();
}
loadBalancer.get_final_result(NUM_THREADS);
return 0;
}