@@ -54,7 +54,7 @@ bool isSystemSafe()
54
54
hasChanged = false ;
55
55
// Loop Through Processes
56
56
for (p = 0 ; p < PN; p++)
57
- // If The Procces Not Executed Before
57
+ // If The Proccess Not Executed Before
58
58
if (finished[p] == 0 )
59
59
{
60
60
// Check: Is This Process Need Resources More Than The Available?
@@ -90,16 +90,9 @@ bool isSystemSafe()
90
90
91
91
bool allocateIfSafe (int processNo, int request[RN])
92
92
{
93
- // Temporary Copies Of: The Process Original Values From All Tables
94
- int tempNeed[RN], tempAlloc[RN], tempAvail[RN];
93
+ // Change Tables Values
95
94
for (r = 0 ; r < RN; r++)
96
95
{
97
- // Store The Original Values
98
- tempAlloc[r] = allocation[processNo][r];
99
- tempNeed[r] = need[processNo][r];
100
- tempAvail[r] = available[r];
101
-
102
- // Change Tables Values
103
96
allocation[processNo][r] += request[r];
104
97
need[processNo][r] -= request[r];
105
98
available[r] -= request[r];
@@ -108,13 +101,14 @@ bool allocateIfSafe(int processNo, int request[RN])
108
101
if (isSystemSafe ())
109
102
return true ;
110
103
111
- // Restore The Original Values
104
+ // Restore Tables Values
112
105
for (r = 0 ; r < RN; r++)
113
106
{
114
- allocation[processNo][r] = tempAlloc [r];
115
- need[processNo][r] = tempNeed [r];
116
- available[r] = tempAvail [r];
107
+ allocation[processNo][r] -= request [r];
108
+ need[processNo][r] += request [r];
109
+ available[r] += request [r];
117
110
}
111
+
118
112
return false ;
119
113
}
120
114
0 commit comments