1 / 6
文档名称:

银行家算法实验报告.docx

格式:docx   大小:21KB   页数:6页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

银行家算法实验报告.docx

上传人:mh900965 2017/12/17 文件大小:21 KB

下载得到文件列表

银行家算法实验报告.docx

文档介绍

文档介绍:银行家算法实验报告
实验目的:了解和掌握银行家算法,进一步熟悉进程和如何避免死锁。
实验内容:
1、主要程序结构
(a)resource allocation algorithm
[l][*]+request[*]>[l][*]

error
//如果要求的资源量+占有的资源总的资源需求量
request[i]>[i]
结束
N
Y
[l][*]=[l][*]+request[*];
[*]=[*]-request[*];
N
Safe(nest)=true
suspend
N

t=true
Y
//t=true可以carry out allocation
结束
(b) test for safety algorithm
注:《--- 》中的内容为未具体写明但说明其功能的程序段
bool safe(struct state new )
{
bool possible = true,found=false;
process rest[n];//正在执行的进程号
int p=n;// 正在执行的进程数量
int currentavail[m];//可用资源的一个副本
《---为rest和currentavail赋值---》
while(possible==true&&p>0)
{
int g=0;
《---寻找可以执行完成的进程---》
if(found==true)
{
int c=0;
《---假设可以执行完的进程以完成,
及currentavail[*]=currentavail[*]+[g][*];---》
rest[g] = -1;
--p;
found =false;
}else{
possible=false;
}
}
return possible;
}
2、实验步骤
1)设计结构体
#ifndef STATE_H_
#define m 3
#define n 5
struct state{
int resource[m];
int available[m];
int claim[n][m];
int alloc[n][m];
} ;
#define STATE_H_
#endif /* STATE_H_ */
2)设计实现程序的结构的具体程序
Safe算法的具体代码
bool safe(struct state new )
{
bool possible = true,found=false;
process rest[n]; //正在执行的进程号
int f=0,p=n;// 正在执行的进程数量
do{
rest[f]=f;
++f;
}while(f<n);
int currentavail[m]; //可用资源的一个副本
int i=0;
do{
currentavail[i]=[i