银行家算法是什么

Banker's algorithm is a deadlock avoidance algorithm. It is named so because this algorithm is used in banking systems to determine whether a loan can be granted or not.

Banker算法是一种避免死锁的算法 。 之所以这样命名,是因为该算法在银行系统中用于确定是否可以授予贷款。

Consider there are n account holders in a bank and the sum of the money in all of their accounts is S. Everytime a loan has to be granted by the bank, it subtracts the loan amount from the total money the bank has. Then it checks if that difference is greater than S. It is done because, only then, the bank would have enough money even if all the n account holders draw all their money at once.

假设在银行中有n帐户持有人,并且他们所有帐户中的金额之和为S 每次银行必须提供贷款时,都会从银行的 金额中减去贷款金额 。 然后,它检查该差是否大于S 之所以这样做,是因为只有那时,所有n帐户持有者立即提取所有资金,银行才会有足够的资金。

Banker's algorithm works in a similar way in computers.

Banker的算法在计算机中的工作方式相似。

Whenever a new process is created, it must specify the maximum instances of each resource type that it needs, exactly.

每当创建新进程时,它都必须准确地指定所需的每种资源类型的最大实例。

Let us assume that there are n processes and m resource types. Some data structures that are used to implement the banker's algorithm are:

让我们假设有n进程和m资源类型。 用于实现银行家算法的一些数据结构是:

1. Available (1. Available)

It is an array of length m. It represents the number of available resources of each type. If Available[j] = k, then there are k instances available, of resource type R(j).

它是长度为m数组 。 它代表每种类型的可用资源数量。 如果Available[j] = k ,则存在k可用实例,资源类型为R(j)

2. Max ( 2. Max)

It is an n x m matrix which represents the maximum number of instances of each resource that a process can request. If Max[i][j] = k, then the process P(i) can request atmost k instances of resource type R(j).

它是一个nxm矩阵,代表进程可以请求的每个资源的最大实例数。 如果Max[i][j] = k ,则进程P(i)最多可以请求k个资源类型R(j)实例。

3. Allocation (3. Allocation)

It is an n x m matrix which represents the number of resources of each type currently allocated to each process. If Allocation[i][j] = k, then process P(i) is currently allocated k instances of resource type R(j).

它是一个nxm矩阵,表示当前分配给每个进程的每种类型的资源数量。 如果Allocation[i][j] = k ,则当前为进程P(i)分配k个资源类型R(j)实例。

4. Need (4. Need)

It is an n x m matrix which indicates the remaining resource needs of each process. If Need[i][j] = k, then process P(i) may need k more instances of resource type R(j) to complete its task.

它是一个nxm矩阵,指示每个进程的剩余资源需求。 如果Need[i][j] = k ,则进程P(i)可能需要k个资源类型R(j)更多实例来完成其任务。

Need[i][j] = Max[i][j] - Allocation [i][j]

资源请求算法 (Resource Request Algorithm)

This describes the behavior of the system when a process makes a resource request in the form of a request matrix. The steps are:

这描述了当进程以请求矩阵的形式发出资源请求时系统的行为。 这些步骤是:

  1. If number of requested instances of each resource is less than the need (which was declared previously by the process), go to step 2.

    如果每个资源的请求实例数少于需求(该资源先前已由流程声明),请转到步骤2。

  2. If number of requested instances of each resource type is less than the available resources of each type, go to step 3. If not, the process has to wait because sufficient resources are not available yet.

    如果每种资源类型的请求实例数少于每种类型的可用资源,请转到步骤3。否则,该过程必须等待,因为还没有足够的资源。

  3. Now, assume that the resources have been allocated. Accordingly do,

    现在,假设已分配资源。 因此,

  4. Available = Available - Requesti
    Allocation(i) = Allocation(i) + Request(i)
    Need(i) = Need(i) - Request(i)
    
    

This step is done because the system needs to assume that resources have been allocated. So there will be less resources available after allocation. The number of allocated instances will increase. The need of the resources by the process will reduce. That's what is represented by the above three operations.

进行此步骤是因为系统需要假定已分配资源。 因此分配后将有较少的可用资源。 分配的实例数将增加。 该过程对资源的需求将减少。 这就是以上三个操作所代表的内容。

After completing the above three steps, check if the system is in safe state by applying the safety algorithm. If it is in safe state, proceed to allocate the requested resources. Else, the process has to wait longer.

完成上述三个步骤后,请通过应用安全算法检查系统是否处于安全状态。 如果处于安全状态,请继续分配请求的资源。 否则,该过程必须等待更长的时间。

安全算法 (Safety Algorithm)

  1. Let Work and Finish be vectors of length m and n, respectively. Initially,

    WorkFinish为长度分别为mn的向量。 原来,

    Work = Available
    Finish[i] =false for i = 0, 1, ... , n - 1.
    
    

    This means, initially, no process has finished and the number of available resources is represented by the Available array.

    这意味着,最初,没有进程完成,可用资源的数量由Available数组表示。

  2. Find an index i such that both

    找到一个索引

    Finish[i] ==false
    Needi <= Work
    
    

    If there is no such i present, then proceed to step 4.

    如果没有此类提示,请继续执行步骤4。

    It means, we need to find an unfinished process whose need can be satisfied by the available resources. If no such process exists, just go to step 4.

    这意味着,我们需要找到一个未完成的过程,其可用资源可以满足其需求。 如果不存在这样的过程,请转到步骤4。

  3. Perform the following:

    执行以下操作:

    Work = Work + Allocation;
    Finish[i] = true;
    
    

    Go to step 2.

    转到步骤2。

    When an unfinished process is found, then the resources are allocated and the process is marked finished. And then, the loop is repeated to check the same for all other processes.

    当发现未完成的过程时,将分配资源并将该过程标记为完成。 然后,重复循环以对所有其他进程进行相同的检查。

  4. If Finish[i] == true for all i, then the system is in a safe state.

    如果对所有i都使用Finish[i] == true ,则系统处于安全状态。

    That means if all processes are finished, then the system is in safe state.

    这意味着,如果所有过程都已完成,则系统处于安全状态。

翻译自: https://www.studytonight.com/operating-system/bankers-algorithm

银行家算法是什么

银行家算法是什么_什么是银行家算法?相关推荐

  1. 蚁群算法java实现_简单蚁群算法 + JAVA实现蚁群算法

    一 引言 蚁群算法(ant colony optimization,ACO),又称蚂蚁算法,是一种用来在图中寻找优化路径的机率型技术.它由Marco Dorigo于1992年在他的博士论文中引入,其灵 ...

  2. labuladong的算法小抄_学会了回溯算法,我终于会做数独了

    经常拿回溯算法来说事儿的,无非就是八皇后问题和数独问题了.那我们今天就通过实际且有趣的例子来讲一下如何用回溯算法来解决数独问题. 一.直观感受 说实话我小的时候也尝试过玩数独游戏,但从来都没有完成过一 ...

  3. 社区发现算法python视频_社区发现FN算法Python实现

    社区发现FN算法Python实现 算法原理 评价指标 结果对比 源码 ​2004年,Newman在GN(Girvan and Newman, 2002)算法的基础上,提出了另外一种快速检测社区的算法, ...

  4. python贝叶斯算法的论文_朴素贝叶斯算法从入门到Python实践

    1,前言 很久不发文章,整理些干货,希望相互学习吧.进入主题,本文主要时说的为朴素贝叶斯分类算法.与逻辑回归,决策树一样,是较为广泛使用的有监督分类算法,简单且易于理解(号称十大数据挖掘算法中最简单的 ...

  5. 使用ga算法解决背包问题_我如何使用算法解决现实生活中的手提背包的背包问题

    使用ga算法解决背包问题 I'm a nomad and live out of one carry-on bag. This means that the total weight of all m ...

  6. 一致性hash算法虚拟节点_一致性哈希算法——虚拟节点

    一致性哈希算法--虚拟节点 一致性哈希算法是分布式系统中常用的算法.比如,一个分布式的存储系统,要将数据存储到具体的节点上,如果采用普通的hash方法,将数据映射到具体的节点上,如key%N,key是 ...

  7. a*算法的优缺点_轻松理解机器学习算法-朴素贝叶斯

    1.预备知识 贝叶斯定理(Bayes' theorem)是概率论中的一个定理,它跟随机变量的条件概率以及边缘概率分布有关.通常事件A在事件B发生的条件下的概率,与事件B在事件A发生的条件下的概率是不一 ...

  8. a*算法的优缺点_五种聚类算法一览与python实现

    大家晚上好,我是阿涛. 今天的主题是聚类算法,小结一下,也算是炒冷饭了,好久不用真忘了. 小目录: 1.K-means聚类2.Mean-Shift聚类3.Dbscan聚类4.层次聚类5.GMM_EM聚 ...

  9. 最短路dijkstra算法详解_最短路径问题---Dijkstra算法详解

    1.Dijkstra算法介绍 · 算法起源: · Djkstra 算法是一种用于计算带权有向图中单源最短路径(SSSP:Single-Source Shortest Path)的算法,由计算机科学家E ...

最新文章

  1. form表单只提交数据而不进行页面跳转的解决方案
  2. Asp.Net统一前后端提示信息方案
  3. 湘潭大学计算机科学与技术录取分数线,2016年湘潭大学计算机科学与技术专业在湖南录取分数线...
  4. Java 流式编程stream
  5. 平衡小车卡尔曼滤波算法
  6. ubuntu18安装vnpyv1.9.2之二
  7. MariaDB -- 数据类型
  8. 强化学习实战(七)【Windows安装星际争霸Ⅰ 强化学习环境教程】
  9. 清除chrome69缓存批处理(保存为.bat格式文件,如test.bat)
  10. 测试一下flash显示图片
  11. 英雄无敌3 Def 文件对应生物列表
  12. 《About Multi-Touch(多点触摸是个什么东西?)》:Sony PS3Eye 介绍、拆解与使用全指南...
  13. 解决——虚拟机无法Ping通主机
  14. php判断4的倍数,4的倍数特征(4的倍数特征规律怎样找)
  15. html自我介绍怎么弄,用html设计一个自我介绍的静态网页
  16. 一个时代的印记:还记得那些年我们逃课去的网吧
  17. 搞线上渠道推广实操这么些年了
  18. 吴恩达《机器学习系列课程》学习笔记(一)
  19. 什么是信息收集?分为哪几类?
  20. css基础--vertical-align

热门文章

  1. [经验教程]2022天猫淘宝618超级红包预售活动入口是什么时候开始什么时间结束优惠力度大吗及2022天猫淘宝618预售红包活动怎么享受免息分期24期?
  2. Wifi可以自动打开并连接指定的网络(Android)
  3. VS Code - 自动保存
  4. 盲盒交友变现系统/脱单盲盒/一元交友/存取小纸条盲盒/分销功能/盲盒交友小程序
  5. Python_7分钟笔记_基础四(函数、递归)
  6. Linux 清理buff/cache缓存
  7. APP调用第三方(微信)登录(最详细的实现流程)
  8. Scratch创意编程(五):Flappy Bird
  9. 访问Oculus需要配置的hosts
  10. 在微型计算机中1mb等于多少字节,1mb的存储容量等于多少字节