设为首页 加入收藏

TOP

C语言实现 操作系统 银行家算法(二)
2014-11-23 19:23:03 来源: 作者: 【 】 浏览:95
Tags:语言 实现 操作系统 银行家 算法
> Available[i]) // 申请的资源比剩余的资源还多!
{
return FALSE;
}
else
{
testAllocate[pId*RCount + i] += reqSource[i];
}
}


if (testStatus(PCount, RCount) == TRUE) // 是一个安全状态
{
// 正式分配
memcpy(Allocation, testAllocate, PCount*RCount*sizeof(int));

free(testAllocate);
return TRUE;
}
else
{
free(testAllocate);
return FALSE;
}


}

// 释放所有的内存空间
int destroy()
{
if (Resource == NULL || Max == NULL || Need == NULL
|| Allocation == NULL || Available == NULL)
{
return FALSE;
}
else
{
free(Resource);
Resource = NULL;
free(Max);
Max = NULL;
free(Need);
Need = NULL;
free(Allocation);
Allocation = NULL;
free(Available);
Available = NULL;


printf("Destroy\n");


return TRUE;
}


}


int main()
{
int p = 0; // 进程数
int r = 0; // 资源分类数


int reqSource[3] = {0, 3, 4};


readData(&p, &r);


// test now status
if (testStatus(p, r) == TRUE)
{
printf("Saft\n");
}
else
{
printf("nonSaft\n");
}



// for test reqSource[3] = {0, 3, 4};
if (request(p, r, 1, reqSource) == TRUE)
{
printf("Allocate\n");
}
else
{
printf("Non-Allocate\n");
}


// 释放所有的内存空间
destroy();



return 0;
}



/* in.txt


5 3 // 进程数 资源种类数
17 5 20 // 各类资源总数


// 最大需求量
5 5 9
5 3 6
4 0 11
4 2 5
4 2 4


// 已分配资源数
2 1 2
4 0 2
4 0 5
2 0 4
3 1 4


// 剩余的资源数
2 3 3


*/


C语言梳理一下,分布在以下10个章节中:


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇一个简单的 C++ 嵌入 Web 服务器 下一篇使用C++实现一个LRU cache

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: