-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1.cpp
More file actions
60 lines (52 loc) · 1.1 KB
/
project1.cpp
File metadata and controls
60 lines (52 loc) · 1.1 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
59
60
#include "window.h"
#include "config.h"
#include "queue.h"
#include <stdlib.h>
#include <time.h>
#include <thread>
#include <unistd.h>
#include <vector>
Window *window;
AppConfig *config;
Queue *queue;
bool running = true;
void exitListener()
{
while (running)
{
char c = getchar();
if(c == 'x')
running = false;
}
}
void updateWindowFct()
{
while (running)
{
usleep(500);
window->updateWindow(queue->queueIds,queue->operationPointId);
}
delete window;
}
int main(int argc, char *argv[])
{
srand(time(NULL));
window = new Window();
queue = new Queue(running);
//config init
config = new AppConfig();
//create control threads
std::thread windowThread(updateWindowFct);
std::thread exitThread(exitListener);
std::vector<std::thread> threads;
for(int i = 0; i < 50; i++){
threads.push_back(std::thread(&Queue::customer, queue, i));
}
windowThread.join();
exitThread.join();
for (int i = 0; i < 50; i++)
{
threads[i].join();
}
return 0;
}