-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundrobin.c
148 lines (138 loc) · 3.31 KB
/
roundrobin.c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*////////////////////////////////////////
// //
// Erick Mikoshi CMPT 312-01 //
// //
// Program #1a - Round Robin Scheduler //
// //
// The purpose of this program is to //
// show how the Round Robin scheduler //
// is executed in the computer, which //
// basically switches between the two //
// processes. It has two mock processes //
// adder and subtractor. Both of which //
// will be executed accordingly. //
// //
// Variable Directory: //
// adpc - Counter for adder //
// supc - Counter for subtractor //
// g - Global counter for processes //
// i - Loop counter //
// //
////////////////////////////////////////*/
#include <stdio.h>
/* Declating and initializing values/functions */
void adder();
void sub();
int apc = 1;
int spc = 1;
int g = 0;
int main () {
int i;
/* Counter to go through 100000 steps */
for (i = 0; i < 100000 ; i++) {
adder();
sub();
/* Every 1000 steps, print the value of g */
if (i % 1000 == 0) {
printf("g is %d", g);
printf("\n");
}
}
return 0;
}
/*//////////////////////////////////
// //
// Adder Function //
// //
// The purpose of this function //
// is to recreate a process that //
// adds to g. The value that is //
// added to g depends on the //
// specific case. It is important //
// to note that once adpc reaches //
// case 6 it loops back around to //
// case 1. Therefore, it keeps //
// running until the desired //
// number of steps are completed. //
// Which is denoted by i. //
// //
//////////////////////////////////*/
void adder(){
/* adpc triggers a specific case depending on its value */
switch (adpc){
case 1:
g++;
adpc = 2;
break;
case 2:
g++;
adpc = 3;
break;
case 3:
g = g + 2;
adpc = 4;
break;
case 4:
g = g + 3;
adpc = 5;
break;
case 5:
g = g + 1;
adpc = 6;
break;
case 6:
g = g + 2;
adpc = 1;
break;
default:
printf("Error");
}
}
/*////////////////////////////////////
// //
// Subtractor Function //
// //
// The purpose of this function //
// is to recreate a process that //
// subtracts from g. The value //
// that is subtracted to g depends //
// on the specific case. It is //
// important to note that once supc //
// reaches case 6 it loops back //
// around to case 1. Therefore, it //
// keeps running until the desired //
// number of steps are completed. //
// Which is denoted by i. //
// //
////////////////////////////////////*/
void sub(){
/* supc triggers a specific case depending on its value */
switch (supc){
case 1:
g--;
supc = 2;
break;
case 2:
g--;
supc = 3;
break;
case 3:
g = g - 2;
supc = 4;
break;
case 4:
g = g - 3;
supc = 5;
break;
case 5:
g = g - 1;
supc = 6;
break;
case 6:
g = g - 2;
supc = 1;
break;
default:
printf("Error");
}
}