•Multiple instances.
•Each process must a priori claim maximum use.
•When a process requests a resource it may have to wait.  
•When a process gets all its resources it must return them in a finite amount of time.

n为进程的数目,m为资源类型的数目

•Available:  Vector of length m.
–If available [j] = k, there are k instances of resource type Rj available.(如果available[j]=k,那么资源Rj有k个实例可用)
•Max: n x m matrix. 
–If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj.(如果Max[i,j]=k,那么进程Pi可以最多请求资源Rj的k个实例)

Data Structures for the Banker’s Algorithm (Cont.):

•Allocation:  n x m matrix. 
–If Allocation[i,j] = k then Pi is currently allocated k instances of Rj.(如果Allocation[i,j]=k,那么进程Pi当前分配了k个资源Rj的实例)
•Need:  n x m matrix.
–If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task.(如果Need[i,j]=k,那么进程Pi 还需要k个资源Rj的实例)

Need [i,j] = Max[i,j] – Allocation [i,j].

Safety Algorithm(安全算法):

1.  Let Work and Finish be vectors of length m and n, respectively.  Initialize(让Work和Finish作为长度为m和n的向量)

Work := Available

Finish [i] = false fori - 1,3, …, n.

2.  Find an isuch that both: (找到i)

(a) Finish [i] = false

(b) Needi£Work

If no such iexists, go to step 4.

3.  Work := Work + Allocationi
Finish[i] := true
go to step 2.

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

Resource-Request Algorithm for Process Pi

•Requesti = request vector for process Pi. 

1.  If Requesti £ Needi go to step 2.  Otherwise, raise error condition, since process has exceeded its maximum claim.

2.  If Requesti £ Available, go to step 3.  Otherwise Pi  must wait, since resources are not available.

3.  Pretend to allocate requested resources to Pi by modifying the state as follows:假定给Pi 分配资源

Available := Available - Requesti;

Allocationi := Allocationi + Requesti;

Needi := Needi – Requesti

4.用安全算法进行检查,看系统是否处于安全状态

•If safe Þ the resources are allocated to Pi.
•If unsafe Þ Pi must wait, and the old resource-allocation state is restored
Example of Banker’s Algorithm:
•5 processes P0 through P4; 3 resource types A (10 instances),
B (5instances), and C (7 instances).(5个进程P0-P4,3类资源A(10个实例),B(5个实例),C(7个实例))
•Snapshot at time T0:(时刻T0的片段)

Allocation       Max       Available

A B C          A B C        A B C

P0  0 1 0          7 5 3         3 3 2

P1  2 0 0          3 2 2

P2  3 0 2          9 0 2

P3  2 1 1          2 2 2

P4  0 0 2          4 3 3

•The content of the matrix. Need is defined to be Max – Allocation. ( Need矩阵的内容可以由Max – Allocation 计算出来)

Need

A B C

P0  7 4 3

P1  1 2 2

P2  6 0 0

P3  0 1 1

P4  4 3 1

•用安全检测算法看能否找到一个安全序列
–Work[]=available=(3,3,2)
–Finish[i]=false  (i=0..4)
–      
–       Work    need   allocation   finish
– P1   3 3 2    1 2 2    2 0 0       T
– P3   5 3 2    0 1 1    2 1 1       T
– P4   7 4 3    4 3 1    0 0 2       T
– P2   7 4 5    6 0 0    3 0 2       T
– P0  10 4 7    7 4 3    0 1 0       T
–存在安全序列:(P1,P3,P4,P2,P0)

注意两点:

1、通常,安全序列不唯一;

2、安全序列中的选取,总是将work中的资源首先分给need(Pi)<=work且max{allocation(Pi)}的进程,剩下的依次类推分配

转载于:https://www.cnblogs.com/cpoint/archive/2012/11/18/2776539.html

银行家算法(Banker's Algorithm)相关推荐

  1. 【操作系统/OS笔记15】死锁的系统模型,死锁的处理办法,银行家算法与死锁检验算法

    本次笔记内容: 11.1 死锁问题 11.2 系统模型 11.3 死锁特征 11.4 死锁处理办法 11.5 死锁预防和死锁避免 11.6 银行家算法 11.7 死锁检测和死锁恢复 文章目录 死锁问题 ...

  2. Java 实现OS进程安全检测算法之银行家算法(Bankers Algorithm)

    文章目录 数据结构介绍: 程序结构 银行家算法bank()函数 安全性算法safe()函数 Java 代码实现 结果测试: 编写银行家算法的模拟程序. 该程序应该能够循环检查每一个提出请求的银行客户并 ...

  3. 银行家算法回顾[JAVA实现]

    为什么80%的码农都做不了架构师?>>>    分析了一下银行家算法,基于银行家算法做了一个小程序. 银行家算法主要用于操作系统进程管理程序中,用于防止死锁. 接下来这段代码将模拟这 ...

  4. 操作系统--用JavaScript实现银行家算法

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

  5. 银行家算法总结及实现

    QUESTION:银行家算法总结及实现? 目录 QUESTION:银行家算法总结及实现? ANSWER: 一:银行家算法介绍 1.1什么是银行家算法 1.2背景 1.3数据结构 1.4算法分析 二:安 ...

  6. 填表法解“银行家算法”问题

    银行家算法( banker's algorithm )由 Dijkstra(1065)提出.他将死锁的问题演示为一个银行家贷款的模型. 一个银行家向一群客户发放信用卡,每个客户有不同的信用额度.每个客 ...

  7. 死锁预防之银行家算法

    死锁预防之银行家算法 死锁 死锁的定义 死锁的产生 死锁的描述 死锁避免算法 银行家算法 设计思想 分析 使用数据结构的描述 使用到的函数 主函数执行的流程 银行家算法的逻辑 完整的程序代码 运行结果 ...

  8. 【避免进程死锁】银行家算法

    一.概述 银行家算法(Banker's Algorithm)是一个避免进程死锁的著名算法,由 Dijkstra 于 1965 年提出.本文为笔者的读书笔记,结构如下: 死锁 银行家算法 例子展示 补充 ...

  9. 银行家算法原理及代码实现

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

最新文章

  1. cmake:在各级目录之间共享变量(cmake cache变量)
  2. 区块链热度背后的资本市场
  3. HSQLDB安装与使用
  4. springboot 获取application参数_(最新 9000 字 )Spring Boot 配置特性解析
  5. 使用计算机来解决实际问题首先要完成,《操作系统》试题库-填空题
  6. VxWorks6.6 pcPentium BSP 使用说明(二):创建启动盘
  7. 更新!在线状态和用户的共存模式保持一致
  8. [转]带花树,Edmonds's matching algorithm,一般图最大匹配
  9. Qt文档阅读笔记-QWebView官方解析与实例
  10. [SSH] 为 GitLab 帐号添加 SSH keys
  11. android模拟器 bridge,ADB (Android Debug Bridge)简介
  12. 蚂蚁如果上市成功,价格崩盘是必然的
  13. 析构函数定义为虚函数原因
  14. java实现ping_java实现Ping示例代码
  15. Python关于节假日的一些处理
  16. 直方图python_Python数据可视化的例子——直方图和核密度曲线
  17. Ubuntu内核版本升级
  18. 关于严格模式的简单介绍
  19. 第一代社交机器人已死:商业模式错误还是生不逢时?
  20. 最长回文子串(马拉车算法)

热门文章

  1. souce insight symble window 关闭
  2. 携创教育:自考本科英语第二外语可以选择哪些?就业前景怎么
  3. 淘宝图片尺寸怎么修改?电脑怎么修改图片尺寸大小?
  4. clumsy网络异常测试
  5. C#编程(五十四)----------Lookup类和有序字典
  6. 事发突然,我中了勒索病毒
  7. 2022-2028全球与中国独立触控板市场现状及未来发展趋势
  8. ubuntu下代理设置
  9. VS.NET2005安装与设置指南
  10. 儿童护眼灯哪个品牌最好?盘点儿童护眼台灯品牌