Home > Back-end >  Bankers algorithm, DFS output all security sequence
Bankers algorithm, DFS output all security sequence

Time:09-26

Want to ask I will find out all the security sequence of DFS algorithm is what's the problem, why the final output of multiple security sequence but not all?
Void Safe (int k)
{
int i, j;
Int flag;
If (k==num_p)//found a security sequence, print
{
count++;
If (count==1) printf (" the current system security! \n");
Printf (" % d a safe sequence: ", count);
For (I=0; i {
Printf (" % d "P, S - & gt; Record [I]);
}
printf("\n");
return;
}
For (I=0; i {
If (Finish [I]==false)
{
flag=true;
For (j=0; J & lt; Num_s; J++)
{
If (Need [I] [j] & gt; The Work [j])//if you can't meet the needs of the current process
flag=false;
}
If (flag==true)//if we can meet the needs of the current process, temporarily in the security queue
{
For (j=0; J & lt; Num_s; J++)
{
The Work [j] +=Allocation [I] [j];
}
Finish [I]=true;
S - & gt; Top++;
S - & gt; Record [S - & gt; top]=I;
Safe (k + 1);//search under a
S - & gt; Top -;//back out of the stack, the process of recovery has just put in
For (j=0; J & lt; Num_s; J++)
{
The Work [j] -=Allocation [I] [j];
}
Finish [I]=false;//recovery
}
}
}
}
I test data and output results:
  • Related