edit

Apr 6, 2012 at 9:03pm
edited
Last edited on Apr 8, 2012 at 11:51pm
Apr 7, 2012 at 11:12am
Not very familiar with the algorithm but I think you deallocate the resources for every process when you should only deallocate one process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(possible == m)
{
	for(int k = 0; k < n; k++) // you deallocate all processes here
	{
		for(int j = 0; j < m; j++)
		{
		        //do math calculations
		        available[j] = holder[k][j] + available[j];
		}
	}
	kickout++;
	possible = 0;
	safe_state[i] = true;
	cout << "\nupdated available vector" << endl;
	cout << available[0] << " " << available[1] << " " << available[2] << " " << available[3] << endl;
					}


Also I think possible should be reset to zero for every iteration of the for loop. You only reset it when it equals m so for the next iteration sometimes it won't be zero.


1
2
3
4
5
	if (!filename)  // I think this should be !infile
	{
		cout << "ERROR READING FILE! " << endl;
		return 0;
	}


You should close infile somewhere too once you don't need it.
Last edited on Apr 7, 2012 at 11:17am
Apr 7, 2012 at 2:27pm
edit
Last edited on Apr 9, 2012 at 3:22am
Apr 7, 2012 at 2:29pm
edit
Last edited on Apr 9, 2012 at 3:22am
Apr 8, 2012 at 3:01am
Studying these two pages suggest you release one process's resources when it is found that its needs can be met by the available vector.

Your program releases every process's resources when it finds one that has needs <= available.

http://www.if.uidaho.edu/~bgray/classes/cs341/doc/banker.html

http://www.cs.colostate.edu/~cs551/CourseNotes/Bankers.html

About my point about possible.

Say m is 4 and process one has 2 needs <= available and process two has 2 needs <= available.

First time thru the if(available[j] >= need[i][j]) loop
possible will be 2.

Possible != m so possible is not reset to zero.

Second time thru the loop m is still 2 and after the loop possible will be 4 (2+2). Now possible == m but process 2 cannot finish (2 out of 4 needs > available) but your code assumes it does and then you make available all the resources of every process.






Apr 8, 2012 at 6:51am
edit
Last edited on Apr 9, 2012 at 3:22am
Apr 8, 2012 at 11:34pm
Please see me after class on Monday, Jacob.

Dr. Lee
Topic archived. No new replies allowed.