-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
53 lines (41 loc) · 1.47 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
#include <iostream>
#include <list>
#include <thread>
#include "Loader.h"
#include "PCB.h"
#include "MMU.h"
#include "Scheduler.h"
#include "Dispatcher.h"
#include "Mutex_queues.cpp"
#include "CPU.h"
#include "Block_manager.h"
int main() {
const int CPU_NUM = 4;
// Loader, MMU, Dispatchers, scheduler, ready_queue (prio queue), io_queue, and done_queue
// and are declared and initialized.
auto pcbs = new M_priority_queue<PCB *>();
auto ready_queue = new M_priority_queue<PCB *>();
auto readyish_queue = new M_queue<PCB *>;
auto blocked_queue = new M_queue<blocking_info *>;
auto done_queue = new M_queue<PCB *>();
auto mmu = new MMU();
auto still_has_work = new bool(true);
auto loader = new Loader();
auto scheduler = new Scheduler(*pcbs, *ready_queue, *readyish_queue, *done_queue, *mmu);
auto threads = std::vector<std::thread>();
// Loader calls init();
loader->init(*mmu, *pcbs);
// Dispatcher threads begin
for (int i = 0; i < CPU_NUM; i++) {
std::thread(Dispatcher::start, mmu, ready_queue, blocked_queue, done_queue, i).detach();
}
//Blocking thread begins
std::thread(Block_manager::start, mmu, readyish_queue, blocked_queue).detach();
// Scheduling process starts in main thread
// Loop begins for scheduler. Continues while there are still jobs to be done
while(done_queue->getSize() < 30) {
scheduler->schedule();
}
std::cout << done_queue->getSize() << " Finish";
return 0;
}