SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating systemAli Haider
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
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
 
Artificial Intelligence Game Search by Examples
Artificial Intelligence Game Search by ExamplesArtificial Intelligence Game Search by Examples
Artificial Intelligence Game Search by ExamplesAhmed Gad
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmUjjawal Poudel
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionBipul Chandra Kar
 

Was ist angesagt? (20)

Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
process creation OS
process creation OSprocess creation OS
process creation OS
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Timestamp protocols
Timestamp protocolsTimestamp protocols
Timestamp protocols
 
Dining philosopher
Dining philosopherDining philosopher
Dining philosopher
 
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)
 
Artificial Intelligence Game Search by Examples
Artificial Intelligence Game Search by ExamplesArtificial Intelligence Game Search by Examples
Artificial Intelligence Game Search by Examples
 
Tic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max AlgorithmTic Tac Toe using Mini Max Algorithm
Tic Tac Toe using Mini Max Algorithm
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 
Dead Lock
Dead LockDead Lock
Dead Lock
 
Brute force method
Brute force methodBrute force method
Brute force method
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Deadlock
DeadlockDeadlock
Deadlock
 

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

7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptxsheraz7288
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemEktaVaswani2
 
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).pptxGovindJha93
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxAbuBakkarShayan
 
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 SystemsPritom Saha Akash
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptxshreesha16
 
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 Approachrahulmonikasharma
 
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 Approachrahulmonikasharma
 
26 to 27deadlockavoidance
26 to 27deadlockavoidance26 to 27deadlockavoidance
26 to 27deadlockavoidancemyrajendra
 
OS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxOS Presentation 1 (1).pptx
OS Presentation 1 (1).pptxFahadAbdullah84
 

Ähnlich wie 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
 

Mehr von 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 MailMatthew Chang
 
Twitter Trend Analyzer
Twitter Trend AnalyzerTwitter Trend Analyzer
Twitter Trend AnalyzerMatthew 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 SwiftMatthew Chang
 
Analyze of Tumblr.com
Analyze of Tumblr.comAnalyze of Tumblr.com
Analyze of Tumblr.comMatthew 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 codeMatthew Chang
 
Logic Circuit Project Final Presentation
Logic Circuit Project Final PresentationLogic Circuit Project Final Presentation
Logic Circuit Project Final PresentationMatthew Chang
 
Programming Language Final PPT
Programming Language Final PPTProgramming Language Final PPT
Programming Language Final PPTMatthew Chang
 
Profile_ Ikwhan chang
Profile_ Ikwhan changProfile_ Ikwhan chang
Profile_ Ikwhan changMatthew Chang
 
모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 Proposal모바일 앱 개발 최종 발표 Proposal
모바일 앱 개발 최종 발표 ProposalMatthew Chang
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final PresentationMatthew Chang
 
Project Avalon Online(Game) Final Report
Project Avalon Online(Game) Final ReportProject Avalon Online(Game) Final Report
Project Avalon Online(Game) Final ReportMatthew Chang
 
Project NGX - Proposal
Project NGX - ProposalProject NGX - Proposal
Project NGX - ProposalMatthew 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 DemonstrationMatthew Chang
 
Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출Db설계 프로젝트 1조 _중간제출
Db설계 프로젝트 1조 _중간제출Matthew Chang
 

Mehr von 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조 _중간제출
 

Kürzlich hochgeladen

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 

Kürzlich hochgeladen (20)

FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

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