-
Notifications
You must be signed in to change notification settings - Fork 1
/
Project1.cpp
62 lines (47 loc) · 1.49 KB
/
Project1.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
55
56
57
58
59
60
61
62
// via : Jinwei Liu, Ghunley Zhang, Kevin Jiang
#include "myscheduler.h"
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h>
int main(int argc, char* argv[])
{
cout << "Test bench via: Jinwei Liu, Ghunley Zhang, Kevin Jiang\n";
Policy policy = PBS; // replace policy: FCFS, STRFwoP, STRFwP, PBS
unsigned int CPU_num = 3; // number of CPU
int thread_num = 5; // number of thread to be scheduled
MyScheduler scheduler(policy, CPU_num);
//intializing variables:
int randomRemainingTime = 0;
int randomPriority = 0;
srand(time(0)); //seeds rand() so it gives random # every time
// create thread
for (int i = 0; i < thread_num; i++) {
randomPriority = rand() % thread_num; // random int from 0 to thread_num -1
randomRemainingTime = rand() % thread_num + 1; // remaining time from 1 to thread_num
scheduler.CreateThread(i, randomRemainingTime, randomPriority, i);
cout << "\t*** Thread #" << i << " has been created. \n" << "\tArrival: " << i << "\tRemaining: " << randomRemainingTime << "\tPriority: " << randomPriority << endl << endl;
}
// print the scheduler policy type
switch (policy)
{
case FCFS:
cout << "FCFS ";
break;
case STRFwoP:
cout << "STRFwoP ";
break;
case STRFwP:
cout << "STRFwP ";
break;
case PBS:
cout << "PBS " << endl;
break;
default:
cout << "Invalid policy!";
throw 0;
break;
}
cout << "running result: " << endl;
scheduler.Go();
return 0;
}