SlideShare a Scribd company logo
Team Project
Presentation
The implementation of Banker’s algorithm, data structure
and parser
Ikwhan Chang (010754107)

Group #10
2-Dec 2016
1
INDEX
• The Definition of Deadlock and Banker’s Algorithm
• Deadlock
• Safe State & Unsafe State
• Banker’s algorithm
• Implementation
• Approach
• UML & Actor model
• Program Design
• Demo
2
Deadlock
3
• A set of blocked processes each holding a resource and waiting to acquire a resource held by another
process in the set.
Four Conditions for Deadlock
1) Mutex Exclusion: each resource can be assigned or used only one process at a request
time
2) Hold and Wait:The process can capture the currently needed resources and request
the new resources needed.
3) No Preemption: Resources already allocated are not forcibly deprived by other
processes.
4) Circular Wait:This situation is intertwined in the shape of a circle.
4
Deadlock Prevention Vs. Avoidance
Deadlock Prevention
• Preventing deadlocks by constraining how requests for resources can be made in the system and how
they are handled (system design).
• The goal is to ensure that at least one of the necessary conditions for deadlock can never hold.
Deadlock Avoidance - Banker’s algorithm
• The system dynamically considers every request and decides whether it is safe to grant it at this point,
• The system requires additional a priori information regarding the overall potential use of each resource for
each process.
• Allows more concurrency.
• => Similar to the difference between a traffic light and a police officer directing traffic.
5
Safe State vs Unsafe State
Safe state
• Status in which the task can be completed
• Safety Sequence:The order in which all processes can complete tasks using available resources
• => If you find the safety sequence, then we can call it is Safe
Unsafe State
• The state that a deadlock can occur
• We cannot find the Safety Sequence
• Deadlock does not occur in safe state, but it can change from safe state to unsafe state.
• The situation where you do not switch from unsafe to deadlock is partial return, if you return in full and go from
unsafe to safe.
• If the next state is unsafe, deny resource allocation
6
Banker’s algorithm - Definition
Suppose we know the “worst case” resource needs of processes in advance
• A bit like knowing the credit limit on your credit cards. (This is why they call it the Banker’s Algorithm)
Observation: Suppose we just give some process ALL the resources it could need…
• Then it will execute to completion.
• After which it will give back the resources.
As a result:
• A process pre-declares its worst-case needs
• Then it asks for what it “really” needs, a little at a time
• The algorithm decides when to grant requests
It delays a request unless:
• It can find a sequence of processes such that it could grant their outstanding need.
• So they would terminate. letting it collect their resources and in this way it can execute everything to completion
7
Banker’s algorithm - Notation
* N: the number of processes on the system
* M: the number of resources present in the system
- Available [1: m]: Indicate which resource i is
- Max [1: n, 1: m]: Expression of the maximum number of resources of type j of process i
- Allocation [1: n, 1: m]: Indicates whether process i has received a resource of type j
- Need [1: n, 1: m]: Max - Allocation. Express how many more can be allocated in the future
-Vectors X,Y
- Work array: an array containing the intermediate result of a resource
- Finish array: a boolean array indicating which process has terminated
8
Banker’s algorithm - Safety Check
Step 1. Assign the resources currently available for work. Finish Set all values of array to false (which means that no processes have
finished yet)
Step 2. Find a process i that does not finish its current run and can satisfy all of the resources it needs the most.
Step 3.Terminate the process and return the resource to finish.

Step 4.When all finish [] entry values are true, the algorithm is ended
How to perform a resource grant using Safety Check
Step 1. Record the newly requested request of each process in the request array
Step 2. If a request in a process requests more than Maximum, it will not accept the request
Step 3. If the condition is less than the maximum value, once you have performed the safety check algorithm
=>The banker's algorithm is implemented in safety and performs deadlock avoidance.
=>There are situations in which a process needs to manage a maximum request for each type, making expensive decisions to perform
and deadlock avoidance.
9
Banker’s algorithm - Example
10
5 processes P0 through P4; 3 resource types A (10 instances), B (5instances), and C (7 instances).
Snapshot at timeT0:
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
Banker’s algorithm - Example
11
The content of the matrix. Need is defined to be 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
The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria.
Approach
Problem
• In our project, we implemented the parser of banker’s algorithm. Since banker’s algorithm is quite simple to implement,
we realized that it is more important to define the data structure of banker’s algorithm as well as parse of it.Thus, we
are focusing on the implementation of parser and data structure.
Development Environment
•Language: C
•Compiler: gcc with c++ 4.2.1 on Apple LLVM v. 8.0.0 target for x86_64-apple-darwin16.3.0
•IDE: Xcode
12
Approach
1) Defined a banker’s information structure
#define A 65
#define MAX_RESOURCE 100
#define MAX_PROCESS 100
#define MAX_RESOURCE_NAME_LEN 40
typedef struct _banker_info
{
char resource_name[MAX_RESOURCE]
[MAX_RESOURCE_NAME_LEN + 1];
int available[MAX_RESOURCE];
int instance_count[MAX_RESOURCE];
int allocation[MAX_PROCESS][MAX_RESOURCE];
int max[MAX_PROCESS][MAX_RESOURCE];
int need[MAX_PROCESS][MAX_RESOURCE];
int process_count;
int resource_count;
int sequence[MAX_PROCESS];
int sequence_count;
int is_prepared;
} banker_info;
13
2) Implemented a scanner module to separate
tokens from files.
Token Types
• ENDFILE: the end of file, 
• ERROR: scan error
• ID:Alphabet exists more than one
• NUM: Decimal exists more than one
• COLON:“:” 
Approach
3) Program command
• load [file_name]: Read Banker’s
information from file
• view: Display the information of Banker
• quit: Exit the program
14
4) Error type for reading the input
• When the allocation value of the process is
larger than the available value of the resource
• When the allocation value of the process is
larger than its max value
• When negative value is input to all values
• When unexpected input is found in the file
format
User Scenario Read information from file
15
User Scenario Display the result
16
Program Design
17
Demo 18
Thanks! 19
Design by Matthew, Chang
http://matthewlab.com

More Related Content

What's hot

First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
Kavya Kapoor
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
Shakshi Ranawat
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
Hema Kashyap
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networking
TamannaSharma70
 
Fp growth
Fp growthFp growth
AI Uninformed Search Strategies by Examples
AI Uninformed Search Strategies by ExamplesAI Uninformed Search Strategies by Examples
AI Uninformed Search Strategies by Examples
Ahmed Gad
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
Mohammad Hafiz-Al-Masud
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
Babar Kamran Ahmed (LION)
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
Amin Omi
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
vinay arora
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
InteX Research Lab
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
vikas dhakane
 
Thread
ThreadThread
Thread
Mohd Arif
 
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Shayek Parvez
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 
Deadlocks
 Deadlocks Deadlocks
Deadlocks
Dilshan Sudaraka
 
Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5
Abhimanyu Mishra
 
Kmp
KmpKmp
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
chauhankapil
 
Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
Kirti Verma
 

What's hot (20)

First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
 
Lecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithmLecture 17 Iterative Deepening a star algorithm
Lecture 17 Iterative Deepening a star algorithm
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networking
 
Fp growth
Fp growthFp growth
Fp growth
 
AI Uninformed Search Strategies by Examples
AI Uninformed Search Strategies by ExamplesAI Uninformed Search Strategies by Examples
AI Uninformed Search Strategies by Examples
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
 
Thread
ThreadThread
Thread
 
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Deadlocks
 Deadlocks Deadlocks
Deadlocks
 
Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5Theory of Automata and formal languages Unit 5
Theory of Automata and formal languages Unit 5
 
Kmp
KmpKmp
Kmp
 
First order predicate logic (fopl)
First order predicate logic (fopl)First order predicate logic (fopl)
First order predicate logic (fopl)
 
Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
 

Similar to The implementation of Banker's algorithm, data structure and its parser

Deadlock
DeadlockDeadlock
Deadlock
Mahershi ACT
 
Deadlock
DeadlockDeadlock
Deadlock
Farhat Shaikh
 
Deadlock Slides
Deadlock SlidesDeadlock Slides
Deadlock Slides
sehrishishaq1
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
sheraz7288
 
Deadlocks Part- II.pdf
Deadlocks Part- II.pdfDeadlocks Part- II.pdf
Deadlocks Part- II.pdf
Harika Pudugosula
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
EktaVaswani2
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
GovindJha93
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptx
AbuBakkarShayan
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
WajeehaBaig
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
Pritom Saha Akash
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
NguyenTienDungK17HL
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
shreesha16
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
hetrathod001
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
rahulmonikasharma
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
rahulmonikasharma
 
26 to 27deadlockavoidance
26 to 27deadlockavoidance26 to 27deadlockavoidance
26 to 27deadlockavoidance
myrajendra
 
Deadlock
DeadlockDeadlock
Deadlock
Mayuri Verma
 
Chapter06.ppt
Chapter06.pptChapter06.ppt
Chapter06.ppt
AvadhRakholiya3
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
Harika Pudugosula
 
OS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxOS Presentation 1 (1).pptx
OS Presentation 1 (1).pptx
FahadAbdullah84
 

Similar to The implementation of Banker's algorithm, data structure and its parser (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock Slides
Deadlock SlidesDeadlock Slides
Deadlock Slides
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
Deadlocks Part- II.pdf
Deadlocks Part- II.pdfDeadlocks Part- II.pdf
Deadlocks Part- II.pdf
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptx
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
 
26 to 27deadlockavoidance
26 to 27deadlockavoidance26 to 27deadlockavoidance
26 to 27deadlockavoidance
 
Deadlock
DeadlockDeadlock
Deadlock
 
Chapter06.ppt
Chapter06.pptChapter06.ppt
Chapter06.ppt
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
OS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxOS Presentation 1 (1).pptx
OS Presentation 1 (1).pptx
 

More from Matthew Chang

Research and Analysis of SSH
Research and Analysis of SSH Research and Analysis of SSH
Research and Analysis of SSH
Matthew Chang
 
Digital Certified Mail (PPT)
Digital Certified Mail (PPT)Digital Certified Mail (PPT)
Digital Certified Mail (PPT)
Matthew Chang
 
Digital Certified Mail
Digital Certified MailDigital Certified Mail
Digital Certified Mail
Matthew Chang
 
Twitter Trend Analyzer
Twitter Trend AnalyzerTwitter Trend Analyzer
Twitter Trend Analyzer
Matthew Chang
 
Image Compression Storage Policy for Openstack Swift
Image Compression Storage Policy for Openstack SwiftImage Compression Storage Policy for Openstack Swift
Image Compression Storage Policy for Openstack Swift
Matthew Chang
 
Urhyme introduction
Urhyme introductionUrhyme introduction
Urhyme introduction
Matthew Chang
 
SDN Project PPT
SDN Project PPTSDN Project PPT
SDN Project PPT
Matthew Chang
 
Analyze of Tumblr.com
Analyze of Tumblr.comAnalyze of Tumblr.com
Analyze of Tumblr.com
Matthew Chang
 
Project Avalon
Project AvalonProject Avalon
Project Avalon
Matthew Chang
 
A new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr codeA new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr code
Matthew Chang
 
Logic Circuit Project Final Presentation
Logic Circuit Project Final PresentationLogic Circuit Project Final Presentation
Logic Circuit Project Final Presentation
Matthew Chang
 
Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPT
Matthew Chang
 
Profile_ Ikwhan chang
Profile_ Ikwhan changProfile_ Ikwhan chang
Profile_ Ikwhan chang
Matthew Chang
 
모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 Proposal모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 Proposal
Matthew Chang
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final Presentation
Matthew Chang
 
Project Avalon Online(Game) Final Report
Project Avalon Online(Game) Final ReportProject Avalon Online(Game) Final Report
Project Avalon Online(Game) Final Report
Matthew Chang
 
Project NGX - Proposal
Project NGX - ProposalProject NGX - Proposal
Project NGX - Proposal
Matthew Chang
 
Report : Android Simple Bug Catch Game(Korean)
Report : Android Simple Bug Catch Game(Korean)Report : Android Simple Bug Catch Game(Korean)
Report : Android Simple Bug Catch Game(Korean)
Matthew Chang
 
Capstone Project Last Demonstration
Capstone Project Last DemonstrationCapstone Project Last Demonstration
Capstone Project Last Demonstration
Matthew Chang
 
Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출Matthew Chang
 

More from Matthew Chang (20)

Research and Analysis of SSH
Research and Analysis of SSH Research and Analysis of SSH
Research and Analysis of SSH
 
Digital Certified Mail (PPT)
Digital Certified Mail (PPT)Digital Certified Mail (PPT)
Digital Certified Mail (PPT)
 
Digital Certified Mail
Digital Certified MailDigital Certified Mail
Digital Certified Mail
 
Twitter Trend Analyzer
Twitter Trend AnalyzerTwitter Trend Analyzer
Twitter Trend Analyzer
 
Image Compression Storage Policy for Openstack Swift
Image Compression Storage Policy for Openstack SwiftImage Compression Storage Policy for Openstack Swift
Image Compression Storage Policy for Openstack Swift
 
Urhyme introduction
Urhyme introductionUrhyme introduction
Urhyme introduction
 
SDN Project PPT
SDN Project PPTSDN Project PPT
SDN Project PPT
 
Analyze of Tumblr.com
Analyze of Tumblr.comAnalyze of Tumblr.com
Analyze of Tumblr.com
 
Project Avalon
Project AvalonProject Avalon
Project Avalon
 
A new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr codeA new interface between smart device and web using html5 web socket and qr code
A new interface between smart device and web using html5 web socket and qr code
 
Logic Circuit Project Final Presentation
Logic Circuit Project Final PresentationLogic Circuit Project Final Presentation
Logic Circuit Project Final Presentation
 
Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPT
 
Profile_ Ikwhan chang
Profile_ Ikwhan changProfile_ Ikwhan chang
Profile_ Ikwhan chang
 
모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 Proposal모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 Proposal
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final Presentation
 
Project Avalon Online(Game) Final Report
Project Avalon Online(Game) Final ReportProject Avalon Online(Game) Final Report
Project Avalon Online(Game) Final Report
 
Project NGX - Proposal
Project NGX - ProposalProject NGX - Proposal
Project NGX - Proposal
 
Report : Android Simple Bug Catch Game(Korean)
Report : Android Simple Bug Catch Game(Korean)Report : Android Simple Bug Catch Game(Korean)
Report : Android Simple Bug Catch Game(Korean)
 
Capstone Project Last Demonstration
Capstone Project Last DemonstrationCapstone Project Last Demonstration
Capstone Project Last Demonstration
 
Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출
 

Recently uploaded

Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 

Recently uploaded (20)

Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 

The implementation of Banker's algorithm, data structure and its parser

  • 1. Team Project Presentation The implementation of Banker’s algorithm, data structure and parser Ikwhan Chang (010754107)
 Group #10 2-Dec 2016 1
  • 2. INDEX • The Definition of Deadlock and Banker’s Algorithm • Deadlock • Safe State & Unsafe State • Banker’s algorithm • Implementation • Approach • UML & Actor model • Program Design • Demo 2
  • 3. Deadlock 3 • A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.
  • 4. Four Conditions for Deadlock 1) Mutex Exclusion: each resource can be assigned or used only one process at a request time 2) Hold and Wait:The process can capture the currently needed resources and request the new resources needed. 3) No Preemption: Resources already allocated are not forcibly deprived by other processes. 4) Circular Wait:This situation is intertwined in the shape of a circle. 4
  • 5. Deadlock Prevention Vs. Avoidance Deadlock Prevention • Preventing deadlocks by constraining how requests for resources can be made in the system and how they are handled (system design). • The goal is to ensure that at least one of the necessary conditions for deadlock can never hold. Deadlock Avoidance - Banker’s algorithm • The system dynamically considers every request and decides whether it is safe to grant it at this point, • The system requires additional a priori information regarding the overall potential use of each resource for each process. • Allows more concurrency. • => Similar to the difference between a traffic light and a police officer directing traffic. 5
  • 6. Safe State vs Unsafe State Safe state • Status in which the task can be completed • Safety Sequence:The order in which all processes can complete tasks using available resources • => If you find the safety sequence, then we can call it is Safe Unsafe State • The state that a deadlock can occur • We cannot find the Safety Sequence • Deadlock does not occur in safe state, but it can change from safe state to unsafe state. • The situation where you do not switch from unsafe to deadlock is partial return, if you return in full and go from unsafe to safe. • If the next state is unsafe, deny resource allocation 6
  • 7. Banker’s algorithm - Definition Suppose we know the “worst case” resource needs of processes in advance • A bit like knowing the credit limit on your credit cards. (This is why they call it the Banker’s Algorithm) Observation: Suppose we just give some process ALL the resources it could need… • Then it will execute to completion. • After which it will give back the resources. As a result: • A process pre-declares its worst-case needs • Then it asks for what it “really” needs, a little at a time • The algorithm decides when to grant requests It delays a request unless: • It can find a sequence of processes such that it could grant their outstanding need. • So they would terminate. letting it collect their resources and in this way it can execute everything to completion 7
  • 8. Banker’s algorithm - Notation * N: the number of processes on the system * M: the number of resources present in the system - Available [1: m]: Indicate which resource i is - Max [1: n, 1: m]: Expression of the maximum number of resources of type j of process i - Allocation [1: n, 1: m]: Indicates whether process i has received a resource of type j - Need [1: n, 1: m]: Max - Allocation. Express how many more can be allocated in the future -Vectors X,Y - Work array: an array containing the intermediate result of a resource - Finish array: a boolean array indicating which process has terminated 8
  • 9. Banker’s algorithm - Safety Check Step 1. Assign the resources currently available for work. Finish Set all values of array to false (which means that no processes have finished yet) Step 2. Find a process i that does not finish its current run and can satisfy all of the resources it needs the most. Step 3.Terminate the process and return the resource to finish.
 Step 4.When all finish [] entry values are true, the algorithm is ended How to perform a resource grant using Safety Check Step 1. Record the newly requested request of each process in the request array Step 2. If a request in a process requests more than Maximum, it will not accept the request Step 3. If the condition is less than the maximum value, once you have performed the safety check algorithm =>The banker's algorithm is implemented in safety and performs deadlock avoidance. =>There are situations in which a process needs to manage a maximum request for each type, making expensive decisions to perform and deadlock avoidance. 9
  • 10. Banker’s algorithm - Example 10 5 processes P0 through P4; 3 resource types A (10 instances), B (5instances), and C (7 instances). Snapshot at timeT0: 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
  • 11. Banker’s algorithm - Example 11 The content of the matrix. Need is defined to be 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 The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria.
  • 12. Approach Problem • In our project, we implemented the parser of banker’s algorithm. Since banker’s algorithm is quite simple to implement, we realized that it is more important to define the data structure of banker’s algorithm as well as parse of it.Thus, we are focusing on the implementation of parser and data structure. Development Environment •Language: C •Compiler: gcc with c++ 4.2.1 on Apple LLVM v. 8.0.0 target for x86_64-apple-darwin16.3.0 •IDE: Xcode 12
  • 13. Approach 1) Defined a banker’s information structure #define A 65 #define MAX_RESOURCE 100 #define MAX_PROCESS 100 #define MAX_RESOURCE_NAME_LEN 40 typedef struct _banker_info { char resource_name[MAX_RESOURCE] [MAX_RESOURCE_NAME_LEN + 1]; int available[MAX_RESOURCE]; int instance_count[MAX_RESOURCE]; int allocation[MAX_PROCESS][MAX_RESOURCE]; int max[MAX_PROCESS][MAX_RESOURCE]; int need[MAX_PROCESS][MAX_RESOURCE]; int process_count; int resource_count; int sequence[MAX_PROCESS]; int sequence_count; int is_prepared; } banker_info; 13 2) Implemented a scanner module to separate tokens from files. Token Types • ENDFILE: the end of file,  • ERROR: scan error • ID:Alphabet exists more than one • NUM: Decimal exists more than one • COLON:“:” 
  • 14. Approach 3) Program command • load [file_name]: Read Banker’s information from file • view: Display the information of Banker • quit: Exit the program 14 4) Error type for reading the input • When the allocation value of the process is larger than the available value of the resource • When the allocation value of the process is larger than its max value • When negative value is input to all values • When unexpected input is found in the file format
  • 15. User Scenario Read information from file 15
  • 16. User Scenario Display the result 16
  • 19. Thanks! 19 Design by Matthew, Chang http://matthewlab.com