欢迎来到一句话经典语录网
我要投稿 投诉建议
当前位置:一句话经典语录 > 心得体会 > 银行家算法的心得体会

银行家算法的心得体会

时间:2016-02-19 23:34

银行家算法

#include#includestruct type{int a;int b;int c;};struct allocation{struct type value;struct allocation *next;};struct max{struct type value;struct max *next;};struct available{struct type value;struct available *next;};struct need{struct type value;struct need *next;};struct path{int value;struct path *next;};struct finish{int value;struct finish *next;};void main(){int p,status=0,i,j,temp,flag=0;struct allocation *allochead,*alloc1,*alloc2,*alloctemp;struct max *maxhead,*max1,*max2,*maxtemp;struct available *availablehead,*workhead,*worktemp;struct need *needhead,*need1,*need2,*needtemp;struct path *pathhead,*path1,*path2,*pathtemp;struct finish *finishhead,*finish1,*finish2,*finishtemp;printf(请输入进程的数目\\\ );scanf(%d,&p);for(i=0;ivalue.a);printf(\\\当前资源类型是 %c\\\,'b');scanf(%d,&alloc1->value.b);printf(\\\当前资源类型是 %c\\\,'c');scanf(%d,&alloc1->value.c);flag++;allochead=alloc1;}else{alloc2=(struct allocation*)malloc(sizeof(struct allocation));printf(\\\当前资源类型是 %c\\\,'a');scanf(%d,&alloc2->value.a);printf(\\\当前资源类型是 %c\\\,'b');scanf(%d,&alloc2->value.b);printf(\\\当前资源类型是 %c\\\,'c');scanf(%d,&alloc2->value.c);alloc1->next=alloc2;alloc1=alloc2;flag++;}}alloc2->next=NULL;flag=0;for(i=0;ivalue.a);printf(\\\当前资源类型是 %c\\\,'b');scanf(%d,&max1->value.b);printf(\\\当前资源类型是 %c\\\,'c');scanf(%d,&max1->value.c);maxhead=max1;flag++;}else{max2=(struct max*)malloc(sizeof(struct max));printf(\\\当前资源类型是 %c\\\,'a');scanf(%d,&max2->value.a);printf(\\\当前资源类型是 %c\\\,'b');scanf(%d,&max2->value.b);printf(\\\当前资源类型是 s %c\\\,'c');scanf(%d,&max2->value.c);max1->next=max2;max1=max2;flag++;}}max2->next=NULL;flag=0; printf(\\\ 请输入可以利用是资源数目\\\ );availablehead=workhead=(struct available*)malloc(sizeof(struct available));printf(\\\ );printf(\\\当前资源类型是 %c\\\,'a');scanf(%d,&availablehead->value.a);printf(\\\当前资源类型是 %c\\\,'b');scanf(%d,&availablehead->value.b);printf(\\\当前资源类型是 %c\\\,'c');scanf(%d,&availablehead->value.c);workhead=availablehead;workhead->value=availablehead->value;flag=0;alloctemp=allochead;maxtemp=maxhead;for(i=0;inext=need2->next=NULL;need1->value.a=(maxtemp->value.a)-(alloctemp->value.a);need1->value.b=(maxtemp->value.b)-(alloctemp->value.b);need1->value.c=(maxtemp->value.c)-(alloctemp->value.c);needhead=need1;flag++;}else{need2=(struct need*)malloc(sizeof(struct need));need2->value.a=(maxtemp->value.a)-(alloctemp->value.a);need2->value.b=(maxtemp->value.b)-(alloctemp->value.b);need2->value.c=(maxtemp->value.c)-(alloctemp->value.c);need1->next=need2;need1=need2;flag++;}maxtemp=maxtemp->next;alloctemp=alloctemp->next;}need2->next=NULL;flag=0;for(i=0;inext=finish2->next=NULL;finish1->value=0;finishhead=finish1;flag++;}else{finish2=(struct finish*)malloc(sizeof(struct finish));finish2->value=0;finish1->next=finish2;finish1=finish2;flag++;}}finish2->next=NULL;flag=0;for(temp=0;tempvalue==0){if((needtemp->value.a<=worktemp->value.a)&&(needtemp->value.b<=worktemp->value.b)&&(needtemp->value.c<=worktemp->value.c)){worktemp->value.a+=alloctemp->value.a;worktemp->value.b+=alloctemp->value.b;worktemp->value.c+=alloctemp->value.c;finishtemp->value=1;if(flag==0){pathhead=path1=path2=(struct path*)malloc(sizeof(struct path));path1->next=path2->next=NULL;path1->value=j+1;pathhead=path1;flag++;}else{path2=(struct path*)malloc(sizeof(struct path));path2->value=j+1;path1->next=path2;path1=path2;flag++;}finishtemp=finishtemp->next;alloctemp=alloctemp->next;needtemp=needtemp->next;}else{ finishtemp=finishtemp->next;alloctemp=alloctemp->next;needtemp=needtemp->next;}}else{ finishtemp=finishtemp->next;alloctemp=alloctemp->next;needtemp=needtemp->next;}}}path2->next=NULL;finishtemp=finishhead;pathtemp=pathhead;for(temp=0;tempvalue==0){printf(\\\ 警告!当前系统是不安全的\\\ );exit(0);}finishtemp=finishtemp->next;}printf(\\\ 当前系统是安全的!\\\ );printf(\\\ 安全序列为: \\\ );for(i=0;ivalue);pathhead=pathhead->next;}}

银行家算法

银行家算法=-- - 1. 安全状态: 在某时刻系统中所有进程可以排列一个安全序列:{P1,P2,`````Pn},刚称此时,系统是安全的. 所谓安全序列{P1,P2,`````Pn}是指对于P2,都有它所需要剩余资源数量不大于系统掌握的剩余的空间资源与所有Pi(j

关于银行家算法,下面的说法哪些是对的

(多选)

BC解释:银行家算法(Banker's Algorithm)是一个避免死锁(Deadlock)的著名算法,A错C对;在避免死锁方法中允许进程动态地申请资源,但系统在进行资源分配之前,应先计算此次分配资源的安全性,若分配不会导致系统进入不安全状态,则分配,否则等待,显然参与系统资源分配,所以B对,D错。

关于银行家算法。

request向量是由你定的,而银行家算法是判断这次请求后是否会构成死锁,如果构成死锁,则取消这次请求。

这样即能避免死锁。

银行家算法实验

P1进程提出的请求,可以分配。

P2进程不能分配,因为请求的B类资源超过了它的最大值。

如果要程序的话,给你这个:#include#include#include#define MAXSIZE 50void main(){ unsigned int Available[MAXSIZE]; \\\/\\\/可利用资源向量 unsigned int Max[MAXSIZE][MAXSIZE]; \\\/\\\/最大需求矩阵 unsigned int Allocation[MAXSIZE][MAXSIZE]; \\\/\\\/已分配矩阵 unsigned int Need[MAXSIZE][MAXSIZE]; \\\/\\\/需求矩阵 unsigned int Request[MAXSIZE]; \\\/\\\/请求向量 unsigned int Work[MAXSIZE]; \\\/\\\/工作向量 bool Finish[MAXSIZE]; \\\/\\\/是否有足够资源分配给进程,使之运行完成 unsigned int SafeSequence[MAXSIZE]; \\\/\\\/安全序列 int i,j; int p; \\\/\\\/请求资源的进程的下标 int temp = 0; \\\/\\\/安全序列下标 int total = 0; int N; int M; printf(请输入进程数N=); scanf(%d,&N); printf(请输入资源种类数M=); scanf(%d,&M); \\\/\\\/用户输入数据,初始化Available数组 printf(初始化可用资源数组:\\\ ); for(i=0; i Need[p][i]) { printf(\\\请求的%c类资源数超过它所宣布的最大值!\\\ ,65+i); break; } if(i == M) \\\/\\\/通过上层检查,继续检查Request <= Available ? { for(i=0; i Available[i]) { printf(\\\尚无足够%c类资源,P%d须等待!\\\ ,65+i,p); break; } } if(i == M) \\\/\\\/尝试分配 { for(i=0; i Work[j]) { break; } if(j == M) \\\/\\\/各类资源都满足Need <= Work { for(j=0; j

银行家算法应用在哪些方面?

银行家算法(Banker's Algorithm)是一个避免死锁(Deadlock)的著名算法,是由艾兹格·迪杰斯特拉在1965年为T.H.E系统设计的一种避免死锁产生的算法。

它以银行借贷系统的分配策略为基础,判断并保证系统的安全运行。

该算法应用方面很广:(1)如银行贷款等。

一定数量的本金要应多个客户的借贷周转,为了防止银行资金无法周转而倒闭,对每一笔贷款,必须考察其是否能限期归还。

(2)利用银行家算法的思想,在高校排课系统中针对选修课程教室安排中的应用,并设计了一种排课的方案,从而使每个教室都能得到充分合理的安排。

(3)还有基于银行家算法的操作系统。

系统中有限的资源要供多个进程使用,必须保证得到的资源的进程能在有限的时间内归还资源,以供其他进程使用资源。

如果资源分配不得到就会发生进程循环等待资源,则进程都无法继续执行下去的死锁现象。

银行家算法

解决死锁,操作系统按照银行家制定的规则为进程分配资源,当进程首次申请资源时,要测试该进程对资源的最大需求量,如果系统现存的资源可以满足它的最大需求量则按当前的申请量分配资源,否则就推迟分配。

当进程在执行中继续申请资源时,先测试该进程本次申请的资源数是否超过了该资源所剩余的总量。

若超过则拒绝分配资源,若能满足则按当前的申请量分配资源,否则也要推迟分配。

声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。联系xxxxxxxx.com

Copyright©2020 一句话经典语录 www.yiyyy.com 版权所有

友情链接

心理测试 图片大全 壁纸图片