SlideShare una empresa de Scribd logo
1 de 45
Using A Petri Net Concepts To organize
The Resources Sharing Between Two
Processors
o How to control resources appeared.
o How to provide the system with the resources at a proper
time to avoid the system to be failed.
o What is a Deadlock.
The problem is :
• A Petri net PN, is a five tuple.
PN = (P, T, F, W, M0)
Where :
P = {P0,..,Pm} a finite set of places
T = {T0,..,Tn} a finite set of transition
F (P x T) U ( T x P) is a set of arcs (flow relation)
W is the weight function
M0 is the initial marking
P ∩ T = ø and P U T ≠ ø
What is Petri net
2
2
a place
a transition
an arc's weight
a token
an arc
The states of a system changes via
enabling and firing rules:
Transition t is enable under marking M
if each input place p of t is marked with at
least w(p,t) tokens,
where w(p,t) is the weight of the arc from p to
t.
An enable transition may fire.
firing of an enabled transition t
remove w(p,t) tokens from each input place
p of t, and
adds w(t,p’) tokens to each output place
Transition Enabling
& Firing
2
2
a place
a transition
an arc's weight
multiplicity 2
a token
an arc
2
2
a place
a transition
an arc's weight
a token
an arc
1. Transitions are usually used to model events (activities) and operations which
change the states in places.
2. Places are used to model states after events have happened
Places can model conditions, resources or objects, like a program variable and
so on.
3. Operations after firing a transition are related with input/output arrows of its
transition.
PN Modeling
it is a process A waiting for a resource held by
process B that is also waiting for a resource held
by A.
What is A Deadlock
A Petri Net is deadlocked if no transition is enable.
Deadlock in Petri Net
8
down(r_1)
down(r_2)
up(r_2)
up(r_1)
down(r_1)
down(r_2)
up(r_2)
up(r_1)
t3
t2
t5
t4
t6
t7
p2
t8
r_1
p1
p3 - critical
p4
p6
p7 - critical
p8
p5
t1
r_2
Deadlock-Free Petri Nets with two Resources
Process A
Process B
red transitions are enable
9
down(r_1)
down(r_2)
up(r_2)
up(r_1)
down(r_2)
down(r_1)
up(r_1)
up(r_2)
t3
t2
t5
t4
t6
t7
p2
t8
r_1
p1
p3 - critical
p4
p6
p7 -
critical
p8
t1
r_2
Potential Deadlock Petri Nets with two Resources
p5
Process A
Process B
10
down(r_1)
down(r_2)
up(r_2)
up(r_1)
down(r_2)
down(r_1)
up(r_1)
up(r_2)
t3
t2
t5
t4
t6
t7
p2
t8
r_1
p1
p3 - critical
p4
p6
p7 -
critical
p8
t1
r_2
Deadlock Petri Net with two Resources
p5
Process A
Process B
Methods for Handling Deadlocks
o Ensure that the system will never enter a deadlock state.
o Allow the system to enter a deadlock state and then recover.
11
Deadlock Prevention
o Four conditions for Deadlock
o Mutual exclusion
o Hold and wait
o No preemption
o Circular wait
o Prevent Deadlock Ensure that at least one of these cannot hold
(any one is false)
o Prevention is better than cure
12
Deadlock Prevention
o Mutual Exclusion –This condition must hold for non-sharable
resources. Ex. Printer. Read only files No need to wait for access. To
make this false all resources should be sharable.
o Hold and Wait –Protocols, (No wait/ No Hold)
o Process must request all resources and be allocated. (No wait)
o Must guarantee that whenever a process requests a resource, it does
not hold any other resources. (No Hold)
13
Deadlock Prevention
o Ex. Copy data from Tape drive to disc, sorts the disk file and then
prints result to a printer.
o No wait: Request Tape drive, Disk file and printer.
o No Hold: Request Tape drive and disk file, Release resources, again
request disk file and printer.
o Dis: Protocol 1 Resource Utilization is less.
14
Deadlock Prevention
o No Preemption –
o If a process that is holding some resources requests another resource that cannot be
immediately allocated to it, then all resources currently being held are released.
o Preempted resources are added to the list of resources for which the process is
waiting.
o Process will be restarted only when it can regain its old resources, as well as the new
ones that it is requesting.
15
Deadlock Prevention
o Circular Wait – impose a total ordering of all resource types, and require that
each process requests resources in an increasing order of enumeration.
16
Avoidance algorithms
o Single instance of a resource type. Use a resource-allocation graph
o Multiple instances of a resource type. Use the banker’s algorithm
17
Banker’s Algorithm
o The Banker’s Algorithm is a resource allocation and deadlock avoidance algorithm.
o It’s developed by Edsger Dijkstra.
o When a new process enter the system, it declares the maximum number of instances that are needed.
o This number cannot exceed the total number of resources in the system.
o When a process requests a resource it may have to wait.
o When a process gets all its resources it must return them in a finite amount of time.
o The Algorithm is actually made up of two separate algorithms:
1- Safety algorithm
2- Resource allocation algorithm
18
19
Safe, Unsafe , Deadlock State
Difference safe VS unsafe state
A safe state guarantee that all processes will finish
From an unsafe state, no such guarantee can be given
20
Save VS unsafe state
o If a system is in safe state  no deadlocks
o A state is safe if it is not deadlocked and there is
some scheduling order in which every P can run to
completion even if all of them suddenly request
maximum # of resources immediately
o A state is safe if there exists a sequence of allocations that allows
all processes to complete
o If a system is in unsafe state  possibility of deadlock.
o Avoidance  ensure that a system will never enter an
unsafe state.
21
Deadlock Avoidance
Algorithm for deadlock avoidance.
1. When a process requests a resource it may have to wait
2. When a process gets all its resources it must return them in a
finite amount of time
2. Banker’s algorithm pretends that resources are granted and checks
if the resulting state is safe.
3. If the resulting state is safe then the resources are granted
o otherwise they are denied ( postponed until later).
Data Structures for the Banker’s Algorithm
o Available: Vector of length m. If available [j] = k, there are k instances of
resource type Rj available.
o Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k
instances of resource type Rj.
o Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k
instances of Rj.
o 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] = Max[i,j] – Allocation [i,j].
22
Data Structures for the Banker’s Algorithm
23
Steps To Find Safe Sequence
24
25
3
3 2 2
t1 t7t4
t2 t5 t8
t3 t6 t9
B
A C
Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
3 2 2
(a) (b)
Demonstration
that the state
in (a) is safe
Free =
26
1
3 2
t1 t7t4
t2 t5 t8
t3 t6 t9
BA C
after t5+: Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
Has Max
A 3 9
B 4 4
C 2 7
3 2 2
(a) (b)
Free =
27
5
3 2
t1 t7t4
t2 t5 t8
t3 t6 t9
BA C
after t6+: Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
Has Max
A 3 9
B 0 -
C 2 7
3 2 2
(a) (b)
(c)
Free =
28
3
t1 t7t4
t2 t5 t8
t3 t6 t9
BA C
after t8+: Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
Has Max
A 3 9
B 0 -
C 7 7
3 2 2
(a) (b)
(d)
Free =
29
7
3
t1 t7t4
t2 t5 t8
t3 t6 t9
BA C
after t9+: Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
3 2 2
(a) (b)
(c)
(d)
Has Max
A 3 9
B 0 -
C 0 -
Free =
30
t1 t7t4
t2 t5 t8
t3 t6 t9
BA C
after t2+ : Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
Has Max
A 9 9
B 0 -
C 0 -
3 2 2
(a) (b)
(c)
Free =
31
10
t1 t7t4
t2 t5 t8
1
t3 t6 t9
BA C
after t3+ : Banker’s Model for a Single Resource
4
7
9
2 5
6
Has Max
A 3 9
B 2 4
C 2 7
Has Max
A 0 -
B 0 -
C 0 -
3 2 2
(a) (b)
(c)
Free =
32
Simplified Model of Banker’s Model for a Single Resource
Has Max
A 3 9
B 2 4
C 2 7
(a)
When B: completes. It gives R = 5
When C: completes. It gives R = 7
When A: completes. It gives R = 10.
Demonstration that the state in (a) is safe
needed
released
A
B
2
5
C
4
97
R
6
33
Simplified Model of Banker’s Algorithm for a Single Resource
- from a safe state to an unsafe state
Has Max
A 4 9
B 2 4
C 2 7
(a)
• When B: completes. It gives R = 4
• There is no sequence that guarantees
completion.
• We went from a safe state to an
unsafe state
Has Max
A 3 9
B 2 4
C 2 7
(b)
Demonstration that the state in (b) is unsafe
was 6
A
B
2
5
C
4
97
R
5
34
Deadlock Avoidance
o The bankers algorithm has multiple resources and multiple
processes.
o We have 3 resources and 5 processes and
o We must get all 5 processes fired so that the system stays in a
stable state
o To keep the system from a deadlock we need to make sure we fire the
correct processes sequence,
o so that the resources assigned and available meet the resources needs.
o If you fire a process and the resources are not met, then your system
will become deadlock and will most likely become in an unstable state.
Example of Banker’s Algorithm
35
• 5 processes P0 through P4; 3 resource types R0 (10 instances), R1 (5 instances), and R2 (7 instances)
• Snapshot at initial time:
•Is the system in a safe state?
–The system is in a safe state since the sequence <P1, P3, P4, P2, P0> satisfies safety criteria
Example of Banker’s Algorithm
36
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
Example of Banker’s Algorithm
37
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
Example of Banker’s Algorithm
38
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
Example of Banker’s Algorithm
39
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
Example of Banker’s Algorithm
40
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
𝑃3 - Finish[3]=T , Work = 7 4 3
Example of Banker’s Algorithm
41
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
𝑃3 - Finish[3]=T , Work = 7 4 3
𝑃4 - Finish[4]=T , Work = 7 4 5
Example of Banker’s Algorithm
42
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
𝑃3 - Finish[3]=T , Work = 7 4 3
𝑃4 - Finish[4]=T , Work = 7 4 5
𝑃0 - Finish[0]=T
Work = 7 5 5
Example of Banker’s Algorithm
43
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
𝑃3 - Finish[3]=T , Work = 7 4 3
𝑃4 - Finish[4]=T , Work = 7 4 5
𝑃0 - Finish[0]=T
Work = 7 5 5
𝑃2 - Finish[2]=T
Work = 10 5 7
Example of Banker’s Algorithm
44
Allocation Max Need Available
A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
A B C
3 3 2
𝑃0 - Finish[0]=F
𝑃1 - Finish[1]=T , Work = 5 3 2
𝑃2 - Finish[2]=F
𝑃3 - Finish[3]=T , Work = 7 4 3
𝑃4 - Finish[4]=T , Work = 7 4 5
𝑃0 - Finish[0]=T
Work = 7 5 5
𝑃2 - Finish[2]=T
Work = 10 5 7
< 𝑃1 , 𝑃3 , 𝑃4 , 𝑃0 , 𝑃2 >
The Result Sequence:
References
1. E.W. Dijkstra. Co-operating sequential processes. In F. Genuys, editor, Program-ming Languages, pages
43112, NewYork, 1968. Academic Press. Reprinted from:Technical Report EWD-123,Technological University,
Eindhoven, the Netherlands,
1965.
2. F.Tricas. Deadlock Analysis, Prevention and Avoidance in Sequential Resource Allo-cation Systems. PhD
thesis, Departamento de Informática
e Ingeniería de Sistemas,
Universidad de Zaragoza, May 2003.
3. F.Tricas, J. M. Colom, and J. Ezpeleta. Some improvements to the banker's algorithm
based on the process structure. In Proceedings of IEEE International Confer-
ence on Robotics and Automation, volume 3, pages 28532858, 2000. San Francisco,
CA, USA.

Más contenido relacionado

La actualidad más candente

Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
Real time-system
Real time-systemReal time-system
Real time-systemysush
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rulesHarini Balamurugan
 
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...vikas dhakane
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressionsSampath Kumar S
 
Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture S. Hasnain Raza
 
AI simple search strategies
AI simple search strategiesAI simple search strategies
AI simple search strategiesRenas Rekany
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin schedulingRaghav S
 
Petri nets by Barkatllah
Petri nets by BarkatllahPetri nets by Barkatllah
Petri nets by BarkatllahBarkat Ullah
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher ProblemRaval Vijay
 

La actualidad más candente (20)

CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Real time-system
Real time-systemReal time-system
Real time-system
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
knowledge representation using rules
knowledge representation using rulesknowledge representation using rules
knowledge representation using rules
 
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...
I.INFORMED SEARCH IN ARTIFICIAL INTELLIGENCE II. HEURISTIC FUNCTION IN AI III...
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions
 
Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture Pipeline processing - Computer Architecture
Pipeline processing - Computer Architecture
 
AI simple search strategies
AI simple search strategiesAI simple search strategies
AI simple search strategies
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
Petri nets by Barkatllah
Petri nets by BarkatllahPetri nets by Barkatllah
Petri nets by Barkatllah
 
asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
 
Dining Philosopher Problem
Dining Philosopher ProblemDining Philosopher Problem
Dining Philosopher Problem
 
Pipelining & All Hazards Solution
Pipelining  & All Hazards SolutionPipelining  & All Hazards Solution
Pipelining & All Hazards Solution
 
Np complete
Np completeNp complete
Np complete
 

Destacado

Colored petri nets theory and applications
Colored petri nets theory and applicationsColored petri nets theory and applications
Colored petri nets theory and applicationsAbu Hussein
 
Inference in first order logic12
Inference in first order logic12Inference in first order logic12
Inference in first order logic12yosser atassi
 
The embedded systems Model
The embedded systems ModelThe embedded systems Model
The embedded systems ModelAJAL A J
 
Modern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationModern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationGioele Ciaparrone
 
Urs Köster - Convolutional and Recurrent Neural Networks
Urs Köster - Convolutional and Recurrent Neural NetworksUrs Köster - Convolutional and Recurrent Neural Networks
Urs Köster - Convolutional and Recurrent Neural NetworksIntel Nervana
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnismVijay Patil
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAMafaz Ahmed
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportVijay Patil
 
RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems Bayar shahab
 
Deployment diagram railway reservation system
Deployment diagram railway reservation systemDeployment diagram railway reservation system
Deployment diagram railway reservation systemmuthumeenakshim
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
Uml deployment diagram
Uml deployment diagramUml deployment diagram
Uml deployment diagramAsraa Batool
 

Destacado (20)

Colored petri nets theory and applications
Colored petri nets theory and applicationsColored petri nets theory and applications
Colored petri nets theory and applications
 
Pg student projects
Pg student projectsPg student projects
Pg student projects
 
3 fol examples v2
3 fol examples v23 fol examples v2
3 fol examples v2
 
Inference in first order logic12
Inference in first order logic12Inference in first order logic12
Inference in first order logic12
 
Ornithopter project
Ornithopter projectOrnithopter project
Ornithopter project
 
The embedded systems Model
The embedded systems ModelThe embedded systems Model
The embedded systems Model
 
ODSC West
ODSC WestODSC West
ODSC West
 
Modern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationModern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentation
 
Urs Köster - Convolutional and Recurrent Neural Networks
Urs Köster - Convolutional and Recurrent Neural NetworksUrs Köster - Convolutional and Recurrent Neural Networks
Urs Köster - Convolutional and Recurrent Neural Networks
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnism
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGA
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism report
 
Deadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWDDeadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWD
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems RTOS- Real Time Operating Systems
RTOS- Real Time Operating Systems
 
Deployment diagram railway reservation system
Deployment diagram railway reservation systemDeployment diagram railway reservation system
Deployment diagram railway reservation system
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
FPGA Introduction
FPGA IntroductionFPGA Introduction
FPGA Introduction
 
Uml deployment diagram
Uml deployment diagramUml deployment diagram
Uml deployment diagram
 

Similar a A petri-net (20)

Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Chapter 5(five).pdf
Chapter 5(five).pdfChapter 5(five).pdf
Chapter 5(five).pdf
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Operating System
Operating SystemOperating System
Operating System
 
Continuous Systems To Discrete Event Systems
Continuous Systems To Discrete Event SystemsContinuous Systems To Discrete Event Systems
Continuous Systems To Discrete Event Systems
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
Deadlock
DeadlockDeadlock
Deadlock
 
Ice
IceIce
Ice
 
Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
Deadlock
DeadlockDeadlock
Deadlock
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
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
DeadlockDeadlock
Deadlock
 
Galvin-operating System(Ch8)
Galvin-operating System(Ch8)Galvin-operating System(Ch8)
Galvin-operating System(Ch8)
 
Ch8: Deadlocks
Ch8: DeadlocksCh8: Deadlocks
Ch8: Deadlocks
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 

Más de Omar Al-Sabek (17)

Google Big Table
Google Big TableGoogle Big Table
Google Big Table
 
Online Certificate Data Mining with Weka
Online Certificate Data Mining with WekaOnline Certificate Data Mining with Weka
Online Certificate Data Mining with Weka
 
Agile Methodology
Agile MethodologyAgile Methodology
Agile Methodology
 
Git
GitGit
Git
 
E payment Project Demo
E payment Project DemoE payment Project Demo
E payment Project Demo
 
Sets c1
Sets c1Sets c1
Sets c1
 
Records c2
Records c2Records c2
Records c2
 
Files c3
Files c3Files c3
Files c3
 
Files c4
Files c4Files c4
Files c4
 
Pointers c5
Pointers c5Pointers c5
Pointers c5
 
Stack c6
Stack c6Stack c6
Stack c6
 
Linked lists c7
Linked lists c7Linked lists c7
Linked lists c7
 
Double linked list c8
Double linked list c8Double linked list c8
Double linked list c8
 
Function procedure c6 c7
Function procedure  c6 c7Function procedure  c6 c7
Function procedure c6 c7
 
Control structures c2 c3
Control structures c2 c3Control structures c2 c3
Control structures c2 c3
 
Programming paradigms c1
Programming paradigms c1Programming paradigms c1
Programming paradigms c1
 
Arrays c4 c5
Arrays c4 c5Arrays c4 c5
Arrays c4 c5
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

A petri-net

  • 1. Using A Petri Net Concepts To organize The Resources Sharing Between Two Processors
  • 2. o How to control resources appeared. o How to provide the system with the resources at a proper time to avoid the system to be failed. o What is a Deadlock. The problem is :
  • 3. • A Petri net PN, is a five tuple. PN = (P, T, F, W, M0) Where : P = {P0,..,Pm} a finite set of places T = {T0,..,Tn} a finite set of transition F (P x T) U ( T x P) is a set of arcs (flow relation) W is the weight function M0 is the initial marking P ∩ T = ø and P U T ≠ ø What is Petri net 2 2 a place a transition an arc's weight a token an arc
  • 4. The states of a system changes via enabling and firing rules: Transition t is enable under marking M if each input place p of t is marked with at least w(p,t) tokens, where w(p,t) is the weight of the arc from p to t. An enable transition may fire. firing of an enabled transition t remove w(p,t) tokens from each input place p of t, and adds w(t,p’) tokens to each output place Transition Enabling & Firing 2 2 a place a transition an arc's weight multiplicity 2 a token an arc 2 2 a place a transition an arc's weight a token an arc
  • 5. 1. Transitions are usually used to model events (activities) and operations which change the states in places. 2. Places are used to model states after events have happened Places can model conditions, resources or objects, like a program variable and so on. 3. Operations after firing a transition are related with input/output arrows of its transition. PN Modeling
  • 6. it is a process A waiting for a resource held by process B that is also waiting for a resource held by A. What is A Deadlock
  • 7. A Petri Net is deadlocked if no transition is enable. Deadlock in Petri Net
  • 8. 8 down(r_1) down(r_2) up(r_2) up(r_1) down(r_1) down(r_2) up(r_2) up(r_1) t3 t2 t5 t4 t6 t7 p2 t8 r_1 p1 p3 - critical p4 p6 p7 - critical p8 p5 t1 r_2 Deadlock-Free Petri Nets with two Resources Process A Process B red transitions are enable
  • 9. 9 down(r_1) down(r_2) up(r_2) up(r_1) down(r_2) down(r_1) up(r_1) up(r_2) t3 t2 t5 t4 t6 t7 p2 t8 r_1 p1 p3 - critical p4 p6 p7 - critical p8 t1 r_2 Potential Deadlock Petri Nets with two Resources p5 Process A Process B
  • 10. 10 down(r_1) down(r_2) up(r_2) up(r_1) down(r_2) down(r_1) up(r_1) up(r_2) t3 t2 t5 t4 t6 t7 p2 t8 r_1 p1 p3 - critical p4 p6 p7 - critical p8 t1 r_2 Deadlock Petri Net with two Resources p5 Process A Process B
  • 11. Methods for Handling Deadlocks o Ensure that the system will never enter a deadlock state. o Allow the system to enter a deadlock state and then recover. 11
  • 12. Deadlock Prevention o Four conditions for Deadlock o Mutual exclusion o Hold and wait o No preemption o Circular wait o Prevent Deadlock Ensure that at least one of these cannot hold (any one is false) o Prevention is better than cure 12
  • 13. Deadlock Prevention o Mutual Exclusion –This condition must hold for non-sharable resources. Ex. Printer. Read only files No need to wait for access. To make this false all resources should be sharable. o Hold and Wait –Protocols, (No wait/ No Hold) o Process must request all resources and be allocated. (No wait) o Must guarantee that whenever a process requests a resource, it does not hold any other resources. (No Hold) 13
  • 14. Deadlock Prevention o Ex. Copy data from Tape drive to disc, sorts the disk file and then prints result to a printer. o No wait: Request Tape drive, Disk file and printer. o No Hold: Request Tape drive and disk file, Release resources, again request disk file and printer. o Dis: Protocol 1 Resource Utilization is less. 14
  • 15. Deadlock Prevention o No Preemption – o If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. o Preempted resources are added to the list of resources for which the process is waiting. o Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. 15
  • 16. Deadlock Prevention o Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. 16
  • 17. Avoidance algorithms o Single instance of a resource type. Use a resource-allocation graph o Multiple instances of a resource type. Use the banker’s algorithm 17
  • 18. Banker’s Algorithm o The Banker’s Algorithm is a resource allocation and deadlock avoidance algorithm. o It’s developed by Edsger Dijkstra. o When a new process enter the system, it declares the maximum number of instances that are needed. o This number cannot exceed the total number of resources in the system. o When a process requests a resource it may have to wait. o When a process gets all its resources it must return them in a finite amount of time. o The Algorithm is actually made up of two separate algorithms: 1- Safety algorithm 2- Resource allocation algorithm 18
  • 19. 19 Safe, Unsafe , Deadlock State Difference safe VS unsafe state A safe state guarantee that all processes will finish From an unsafe state, no such guarantee can be given
  • 20. 20 Save VS unsafe state o If a system is in safe state  no deadlocks o A state is safe if it is not deadlocked and there is some scheduling order in which every P can run to completion even if all of them suddenly request maximum # of resources immediately o A state is safe if there exists a sequence of allocations that allows all processes to complete o If a system is in unsafe state  possibility of deadlock. o Avoidance  ensure that a system will never enter an unsafe state.
  • 21. 21 Deadlock Avoidance Algorithm for deadlock avoidance. 1. When a process requests a resource it may have to wait 2. When a process gets all its resources it must return them in a finite amount of time 2. Banker’s algorithm pretends that resources are granted and checks if the resulting state is safe. 3. If the resulting state is safe then the resources are granted o otherwise they are denied ( postponed until later).
  • 22. Data Structures for the Banker’s Algorithm o Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. o Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj. o Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. o 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] = Max[i,j] – Allocation [i,j]. 22
  • 23. Data Structures for the Banker’s Algorithm 23
  • 24. Steps To Find Safe Sequence 24
  • 25. 25 3 3 2 2 t1 t7t4 t2 t5 t8 t3 t6 t9 B A C Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 3 2 2 (a) (b) Demonstration that the state in (a) is safe Free =
  • 26. 26 1 3 2 t1 t7t4 t2 t5 t8 t3 t6 t9 BA C after t5+: Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 Has Max A 3 9 B 4 4 C 2 7 3 2 2 (a) (b) Free =
  • 27. 27 5 3 2 t1 t7t4 t2 t5 t8 t3 t6 t9 BA C after t6+: Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 Has Max A 3 9 B 0 - C 2 7 3 2 2 (a) (b) (c) Free =
  • 28. 28 3 t1 t7t4 t2 t5 t8 t3 t6 t9 BA C after t8+: Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 Has Max A 3 9 B 0 - C 7 7 3 2 2 (a) (b) (d) Free =
  • 29. 29 7 3 t1 t7t4 t2 t5 t8 t3 t6 t9 BA C after t9+: Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 3 2 2 (a) (b) (c) (d) Has Max A 3 9 B 0 - C 0 - Free =
  • 30. 30 t1 t7t4 t2 t5 t8 t3 t6 t9 BA C after t2+ : Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 Has Max A 9 9 B 0 - C 0 - 3 2 2 (a) (b) (c) Free =
  • 31. 31 10 t1 t7t4 t2 t5 t8 1 t3 t6 t9 BA C after t3+ : Banker’s Model for a Single Resource 4 7 9 2 5 6 Has Max A 3 9 B 2 4 C 2 7 Has Max A 0 - B 0 - C 0 - 3 2 2 (a) (b) (c) Free =
  • 32. 32 Simplified Model of Banker’s Model for a Single Resource Has Max A 3 9 B 2 4 C 2 7 (a) When B: completes. It gives R = 5 When C: completes. It gives R = 7 When A: completes. It gives R = 10. Demonstration that the state in (a) is safe needed released A B 2 5 C 4 97 R 6
  • 33. 33 Simplified Model of Banker’s Algorithm for a Single Resource - from a safe state to an unsafe state Has Max A 4 9 B 2 4 C 2 7 (a) • When B: completes. It gives R = 4 • There is no sequence that guarantees completion. • We went from a safe state to an unsafe state Has Max A 3 9 B 2 4 C 2 7 (b) Demonstration that the state in (b) is unsafe was 6 A B 2 5 C 4 97 R 5
  • 34. 34 Deadlock Avoidance o The bankers algorithm has multiple resources and multiple processes. o We have 3 resources and 5 processes and o We must get all 5 processes fired so that the system stays in a stable state o To keep the system from a deadlock we need to make sure we fire the correct processes sequence, o so that the resources assigned and available meet the resources needs. o If you fire a process and the resources are not met, then your system will become deadlock and will most likely become in an unstable state.
  • 35. Example of Banker’s Algorithm 35 • 5 processes P0 through P4; 3 resource types R0 (10 instances), R1 (5 instances), and R2 (7 instances) • Snapshot at initial time: •Is the system in a safe state? –The system is in a safe state since the sequence <P1, P3, P4, P2, P0> satisfies safety criteria
  • 36. Example of Banker’s Algorithm 36 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2
  • 37. Example of Banker’s Algorithm 37 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F
  • 38. Example of Banker’s Algorithm 38 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2
  • 39. Example of Banker’s Algorithm 39 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F
  • 40. Example of Banker’s Algorithm 40 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F 𝑃3 - Finish[3]=T , Work = 7 4 3
  • 41. Example of Banker’s Algorithm 41 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F 𝑃3 - Finish[3]=T , Work = 7 4 3 𝑃4 - Finish[4]=T , Work = 7 4 5
  • 42. Example of Banker’s Algorithm 42 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F 𝑃3 - Finish[3]=T , Work = 7 4 3 𝑃4 - Finish[4]=T , Work = 7 4 5 𝑃0 - Finish[0]=T Work = 7 5 5
  • 43. Example of Banker’s Algorithm 43 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F 𝑃3 - Finish[3]=T , Work = 7 4 3 𝑃4 - Finish[4]=T , Work = 7 4 5 𝑃0 - Finish[0]=T Work = 7 5 5 𝑃2 - Finish[2]=T Work = 10 5 7
  • 44. Example of Banker’s Algorithm 44 Allocation Max Need Available A B C P0 0 1 0 P1 2 0 0 P2 3 0 2 P3 2 1 1 P4 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 A B C 3 3 2 𝑃0 - Finish[0]=F 𝑃1 - Finish[1]=T , Work = 5 3 2 𝑃2 - Finish[2]=F 𝑃3 - Finish[3]=T , Work = 7 4 3 𝑃4 - Finish[4]=T , Work = 7 4 5 𝑃0 - Finish[0]=T Work = 7 5 5 𝑃2 - Finish[2]=T Work = 10 5 7 < 𝑃1 , 𝑃3 , 𝑃4 , 𝑃0 , 𝑃2 > The Result Sequence:
  • 45. References 1. E.W. Dijkstra. Co-operating sequential processes. In F. Genuys, editor, Program-ming Languages, pages 43112, NewYork, 1968. Academic Press. Reprinted from:Technical Report EWD-123,Technological University, Eindhoven, the Netherlands, 1965. 2. F.Tricas. Deadlock Analysis, Prevention and Avoidance in Sequential Resource Allo-cation Systems. PhD thesis, Departamento de Informática e Ingeniería de Sistemas, Universidad de Zaragoza, May 2003. 3. F.Tricas, J. M. Colom, and J. Ezpeleta. Some improvements to the banker's algorithm based on the process structure. In Proceedings of IEEE International Confer- ence on Robotics and Automation, volume 3, pages 28532858, 2000. San Francisco, CA, USA.