.
int i=0,j=0;
printf(\==================\\n\
//可分配资源
printf(\输入可分配资源\\n\
scanf(\
//最大需求矩阵MAX
printf(\输入最大需求矩阵%dx%d\\n\ for (i=0;i scanf(\ } //已分配矩阵Alloc printf(\输入已分配矩阵%dx%d\\n\ for (i=0;i scanf(\ } //需求矩阵 printf(\输入需求矩阵%dx%d\\n\ 开 始 手 动 配 置 资 源 精选文档 . for (i=0;i scanf(\ } printf(\结束配置资==================\\n\ } void loadConfig() { FILE *fp1; if ((fp1=fopen(\ { printf(\没有发现配置文件,请手动输入!!!\\n\ setConfig(); } else{ int i=0; printf(\发现配置文件,开始导入..\\n\ //可分配资源 fscanf(fp1,\精选文档 源 . //最大需求矩阵MAX for (i=0;i fscanf(fp1,\ } //已分配矩阵Alloc for (i=0;i fscanf(fp1,\ } //需求矩阵 for (i=0;i fscanf(fp1,\ } } } //试探分配 精选文档 . void ProbeAlloc(int process,RES *res) { Available.A -= res->A; Available.B -= res->B; Available.C -= res->C; Allocation[process].A += res->A; Allocation[process].B += res->B; Allocation[process].C += res->C; Need[process].A -= res->A; Need[process].B -= res->B; Need[process].C -= res->C; } //若试探分配后进入不安全状态,将分配回滚 void RollBack(int process,RES *res) { Available.A += res->A; Available.B += res->B; Available.C += res->C; Allocation[process].A -= res->A; Allocation[process].B -= res->B; 精选文档 . Allocation[process].C -= res->C; Need[process].A += res->A; Need[process].B += res->B; Need[process].C += res->C; } //安全性检查 bool SafeCheck() { RES Work; Work.A = Available.A; Work.B = Available.B; Work.C = Available.C; bool Finish[PNUMBER] = {false,false,false}; int i; int j = 0; for (i = 0; i < PNUMBER; i++) { //是否已检查过 if(Finish[i] == false) { //是否有足够的资源分配给该进程 精选文档