OS-银行家算法

银行家算法

1、need是申请资源部分;

2、max是需要资源;

3、allocation 是分配资源;

4、rest结构提是指剩余部分的资源;

5、分配算法就是need小于rest就表示该资源可以成功;

6、这里还要将没有加入部分加入一个counter里面,保存--在其他释放资源后有可能会执行,有可能会等待,flag标记2时候一定不可能在存在的;

7、flag数组里面0--表示为不成立,1--表示成立

typedef int data;
typedef struct node{
    data A;
    data B;
    data C;
}node;
typedef struct Process{
    node Max;
    node Allocation;
    node Need;
    unsigned short flag;
}process;
typedef struct rest{
    node Avaliable;
}rest;
void InitialArr(process * pro,const int len,int *flag)
{
    fprintf(stdout, "in order as you input:max(d,d,d)");
    for(int i=0;i
   
   
    
    =b.A&&a.B>=b.B&&a.C>=b.C)
    {
        flag=1;
        return flag;
    }
    return flag;
}
void Set_process(process * pro,const int len,int * flag,process * cun,process * Queue,rest  *res,int * local)
{
    int j=0,k=0;
    for(int i=0;i
    
    
     
     Avaliable, pro[i].Need)==1&&flag[i]==0)
        {
            res->Avaliable.A+=pro[i].Need.A;
            res->Avaliable.B+=pro[i].Need.B;
            res->Avaliable.C+=pro[i].Need.C;
            cun[j]=pro[i];
            flag[i]=1;
            local[j]=i;
            j++;
        }
        else
        {
            pro[i].flag++;
            Queue[k++]=pro[i];
        }
    }
}
void Queue_list(process * Queue,const int len,rest *res,int * local,int * flag)
{
    process * temp=malloc(len*sizeof(process));
    int * s=malloc(len*sizeof(int));
    int k=0;
    for(int i=0;i
     
     
      
      Avaliable,Queue[i].Need)==1&&flag[local[i]]==0)
        {
            res->Avaliable.A+=Queue[i].Need.A;
            res->Avaliable.B+=Queue[i].Need.B;
            res->Avaliable.C+=Queue[i].Need.C;
            flag[local[i]]=1;
        }
        else
        {
            Queue[i].flag++;
            temp[k]=Queue[i];
            s[k]=i;
            k++;
        }
    }
    for(int i=0;i<=k;i++)
    {
        if(Check_ask(res->Avaliable,temp[i].Need)==1&&local[s[i]]==0)
        {
            res->Avaliable.A+=temp[i].Need.A;
            res->Avaliable.B+=temp[i].Need.B;
            res->Avaliable.C+=temp[i].Need.C;
        }
        else
        {
            continue;
        }
    }
    free(temp);
    free(s);
}


     
     
    
    
   
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值