CY2003 Computer Systems Lecture 7 Petri net. © LJMU, 2004CY2003- Week 72 Overview Petri net...

24
CY2003 Computer Systems Lecture 7 Petri net

Transcript of CY2003 Computer Systems Lecture 7 Petri net. © LJMU, 2004CY2003- Week 72 Overview Petri net...

CY2003Computer Systems

Lecture 7

Petri net

© LJMU, 2004 CY2003- Week 7 2

Overview

• Petri net– concepts– Petri net representation– Firing a transition– Marks (Tokens)

• Modeling with Petri net – Events and condition

• Mutual exclusion

Petri Net: Background

© LJMU, 2004 CY2003- Week 7 4

Background• A petri net was introduced by a German

mathematician and used to model a system– Condition: a Boolean description of the state of the

system – Event: an action that depends on the state of the

system• Petri net is a graphical and mathematical tools for

the analysis of discrete event dynamic systems.– The system model is represented by a set of

conditions and a set of events – A condition is represented by a place and an event by

transition.

© LJMU, 2004 CY2003- Week 7 5

Petri net representation

• In the graphical representation for a of petri net: – a place is drawn as a circle – a transition is drawn as a bar.

t2 t3t1

p1 p3

p2

© LJMU, 2004 CY2003- Week 7 6

Marks (Tokens)

• A marking M is an assignment of tokens (dots) to places of a petri net.

• Dots are placed in the circle to represent place in which its condition is satisfied – e.g. a resource is available or operation in a process

• The marking can be represented as M = (1,1,0)

© LJMU, 2004 CY2003- Week 7 7

Marks (Tokens)

• A place can have more than one token and therefore can represent a queue – (e.g. a buffer holding several processes).

t2 t3t1

p1 p3

p2

© LJMU, 2004 CY2003- Week 7 8

Firing a transition

• Executing a marked Petri net causes the number and positions of the token to change. The rules for the execution are:– A transition is enabled if all its input places contain at

least one token. – Any enabled transition may fire– Firing of a transition results in one token being

removed from each of its input places and being deposited of its output places

– Execution halts when there are no enabled transitions. – Each time a transitions fires, the marking of the petri

net will change.

© LJMU, 2004 CY2003- Week 7 9

Example

t2 t3 t1

p1 p3

p2

1 1 0

0 0 1

t2t1

0 1 0

t3

M2

M0

M1

© LJMU, 2004 CY2003- Week 7 10

Modelling with petri net

• Petri net is mainly used for modelling. – Many systems can be modelled by petri net.

• The system may be of many different kinds like computer hardware, computer software, physical system and so on. – Petri net is used to model the occurrence of various

events and activities in the system.

© LJMU, 2004 CY2003- Week 7 11

Concurrency and Synchronisation

• Concurrency means that two events could take place in parallel, without interfering with one another.– By having two places as input conditions to the same

transition, these two conditions become synchronised.

t2

t3

t1

p1

p3

p2 p4

p6

p7

p5

t5

t4

Concurrency Synchronization

© LJMU, 2004 CY2003- Week 7 12

Conflict

• Two transitions t1 and t2

are said to be conflict if either t1 or t2 can occur but

not both of them, – i.e., when there is one

place that is acting as input condition to a number of transitions.

– Therefore, only one transition can be fire.

tk

Pi

tj

Mutual exclusion

© LJMU, 2004 CY2003- Week 7 14

Recall

• Mutual exclusion is a technique of defining entry and exit code so that at most one process is allowed to access the critical region at the same time. – The idea is that no process is allowed to enter the

critical region, unless it checks that no other process is executing its own critical region.

• Mutual exclusion can be represented in Petri net using conflict.

© LJMU, 2004 CY2003- Week 7 15

Mutual exclusion• The place s represents

the permission to enter the critical region and there must be token in p1

and p2.

– If both processes want to enter the critical region simultaneously, then transition t1 and t2 are in

conflict – i.e., only one of them can

fire.

t1 t2

p2 p1

s Critical

section

Critical

section

Process 2 Process 1

© LJMU, 2004 CY2003- Week 7 16

Producer consumer problem

• bounded buffer

n

Produce

Put in

buffe

B

Consume

Remove

from buffer

ProducerConsumer

© LJMU, 2004 CY2003- Week 7 17

Analysis of Petri net

• Petri nets are capable of modelling a large variety of systems and properly representing the interactions between the various actions which can occur. – The strength of Petri net is its capability to model the

system. • However, modelling by itself is of little use and its necessary

to analyse the modelled system. This could lead to important insights into the behaviour of the modelled system.

© LJMU, 2004 CY2003- Week 7 18

Reachibility• Given a Petri net, one would like to know which marking Mr can be reached from an

initial marking M0.

• Example: For the Petri net of the bounded buffer consumer producer problem, M0 = (1, 0, 1, 0, 0, n) and M1 = (0, 1, 1, 0, 0, n)

– is immediately reachable from the marking of M0.

© LJMU, 2004 CY2003- Week 7 19

Safeness

• A place in a Petri net is save if the number of tokens in that place never exceeds one.– A petri net is same if all its places are safe.

what does this Petri net do? Is it safe?

E2

M2

C2 M3

E3

C3

M4

E4

C4

M5

E5 C5

M1

E1

C1

© LJMU, 2004 CY2003- Week 7 20

Boundedness

• A place is k-safe or k-bounded if the number of tokens in that place cannot exceed an integer k.– Therefore a place is 1-bounded is simply a safe place.

• Example: – The Petri net for the producer/consumer problem with

a bounded buffer, is it safe? Bounded?

– The Petri net for the producer/consumer problem with a unbounded buffer, is it bounded? Why?

© LJMU, 2004 CY2003- Week 7 21

Conservation

• A Petri net with an initial marking M0, is strictly conservative, – if for all the reachable marking, the total number of

tokens in each marking is exactly the same as the initial marking.

• A Petri net can be used to model resource allocation systems. In this systems some tokens may represents the resources. – Therefore, in such Petri nets conservation is an

important property such that resources can neither be created nor destroyed.

© LJMU, 2004 CY2003- Week 7 22

Liveness• Another problem that could occur in resource allocation is deadlock.

– A deadlock in a Petri net is a transition (or a set of transition) which cannot fire. – A transition is alive if it is not deadlock. – A transition is live in a marking M if it is potentially fireable in every marking in

the Petri net.

© LJMU, 2004 CY2003- Week 7 23

Exercises

• For the following Petri net, indicate whether each is bounded, live, and conservative or not and show why?

p1

p2 p4

p3

p1

p2

p3

t1

t2t3

t1

t2

t3

p1

p2p3

p4

t1

t2

t3

t4

© LJMU, 2004 CY2003- Week 7 24

Summary

• Petri net– concepts– Petri net representation– Firing a transition– Marks (Tokens)

• Modeling with Petri net – Events and condition

• Mutual exclusion