Title: Models of Concurrency Mana, Pnueli
1Models of Concurrency(Mana, Pnueli)
- Marjan Sirjani
- University of Tehran
- Formal Methods Laboratory
2- Models of Concurrency
- Manna, chapter 1,2
3Chapter 1
- 1.1 The Generic Model
- 1.2 Model 1 Transition Diagrams
- 1.3 Model 2 Shared-Variables Text
- 1.4 Semantics of Shared-Variables Text
- 1.5 Structural Relations Between Statements
- 1.6 Behavioral Equivalence
- 1.7 Grouped Statements
- 1.8 Semaphore Statements
- 1.9 Region Statements
- 1.10 Model 3 Message-Passing Text
- 1.11 Model 4 Petri-Nets
4SystemsReactive or Transformational
5Transformational
- A transformational program produce a result at
the end - It can be considered as a function from an
initial state to a final state - Can be formulated by specifying the relation
between the initial and final states - predicate logic
6Reactive
- Goal maintain some ongoing interaction with the
environment - An OS
- Systems for controlling mechanical processes
7Reactive (cont.)
- Some reactive programs are not expected to
terminate - They cannot specified by a relation between
initial and final states - Must specified by their unending behavior
- Temporal logic instead of predicate logic
8Reactivity and Concurrency
- Reactivity and concurrency are closely related
- The program and its environment act
- Concurrently in reactive programs
- Sequentially in transformational programs
- Parallel processes should be analyzed as a
reactive system - Even if the whole program has a transformational
role
9Communication and Coordination
- Communication and coordination play an important
role in achieving concurrency - Many models have been proposed
10Communication and Coordination (cont.)
- Communication
- Shared variables
- Message passing
- Remote procedure calls
- Coordination
- Semaphores
- Critical regions
- Monitors
- Handshaking
- Rendezvous
- Asynchronous transmission
11The Generic Model
12Why a generic model?
- A generic model for modeling reactive systems
- Uniform treatment of all models
- The theory of specification and verification of
reactive systems will be formulated in the
generic model
13The Generic Model
- Using an underlying first-order language with
these elements - V Vocabulary
- E Expressions
- A Assertions
- I - Interpretations
14Vocabulary
- A countable set of typed variables
- Having two forms
- Data variables
- Range over data domains used in programs, such as
Booleans, integers, or lists. - Control variables
- Indicate progress in the execution of a program,
range over locations in the program.
15Expressions
- Expressions are constructed from
- variables of V
- constants
- such as 0, ?(empty list), ? (empty set)
- functions
- such as ,, U
- predicates
- such as gt, null, and ?
- over the appropriate domains (such as integers,
lists, and sets) - For example x3y hd(u) tl(v) A U B
16Assertions
- Assertions are constructed from
- Boolean expressions using boolean connectives and
quantification(?,?) over some variables that
appear in the expressions - For example ?x (xgt0) ??y (x y.y)
17Interpretation
- An interpretation I ?I of a set of typed
variables V ? V is a mapping that assigns to each
variable y ? V a value Iy in the domain of y - If I?T, we say I satisfies ? I ?
- (? is a boolean expression or more generally
an assertion)
18Basic Transition System
- A basic transition system (?,?,?,?)
- Represents a reactive program.
- ?u1,,u2 ? V a finite set of flexible state
variables - ? a set of states.
- ? a finite set of transitions.
- ? an initial condition.
19State variables
- ?u1,,u2 ? V a finite set of flexible state
variables - Variables can be
- Data variables
- Explicitly declared and manipulated
- Control variables
- Represent progress in the execution of the
program (label of a statement)
20Set of states
- ? - a set of states.
- Each state s in ? is an interpretation of ?,
assigning to each variable u in ? a value over
its domain, denoted by su - A state s that satisfies an assertion ?, i.e., s
? , is sometimes referred to as ?state
21Transitions set
- ? - a finite set of transitions.
- Each transition ? in T represents a
state-transforming action of the system - It is defined as a function ? ? ? 2 ? that
maps a state s in ? into the (possibly empty) set
of states ?(s) that can be obtained by applying
action ? to state s
22Initial condition
- ? - an initial condition.
- This assertion characterizes the states at which
execution of the program can begin - A state s that satisfies ?, i.e., s ? , is
called an initial state
23The Transition Relation ??
- Each transition ? is characterized by an
assertion, called the transition relation
??(?,?) - It relates the values of the state variables s to
their values in a successor state s obtained by
applying ? to s
24Transition relation
- ??(?,?) C? (?) ? (y1e1) ? ?(ykek)
- The transition relation consists of the following
elements - Enabling condition C? (?)
- Conjunction of modification statements (y1e1)
? ?(ykek)
25 26Enabled and disabled transitions
- For a transition ? in ? and a state s in ? we
say - ? is enabled on s if ?(s)??
- ? is disabled on s if ?(s)?
27Idling and diligent transitions
- In the idling transition ?I models the behavior
in which there is no change - ??I T
- A state s is called terminal if the only
transition that is enable on s is the idling
transition ?I - The transitions other than idling are called
diligent
?I(s) s
28Computation
- Computation infinite sequence of states
- ? s0, s1, s2,
- A computation satisfies the following conditions
- Initiation the first state s0 is initial
- Consecution For each pair of consecutive states
in ?, si1 ? ? for some ? in ? - Diligence Either the sequence contains infinite
diligent steps or it contains a terminal state
29- Computation prefix every finite prefix of a
computation - Reachable states it appears in some computation
of the system
30Concrete models
- Model 1 Transition Diagram
- Model 2 Shared-Variables text
- Model 3 Message-Passing text
- Model 4 Petri Nets
31Transition Diagrams
32Model 1 Transition diagrams
- In this model, a program P has the following form
- PdeclarationP1 P2 Pm m?1
- Pi are processes
- Data variables Yy1, , yn n?1
- Declared at the head of the program
- Shared for all the processes
33Declarations
- Declarations appear at the head of the program
- mode var, ,var type where ?i
- mode in, local, out
- type
- basic ( int, char)
- structured ( array, list, set)
- assertion ?i imposes constraint on the initial
values of some of the variables in this statement
34Example
- in k, n integer where 0?k?n
- local y1,y2 integer where y1n ? y21
- out b integer where b 1
- Data precondition of the program
- ? 0?k?n ? y1n ? y21 ? b1
35Processes
- Each process Pi is represented by a transition
diagram (directed graph) - Nodes locations
- For Pi Li li0, li1 , , liti
- One entry and zero or more exit locations
- Edges (atomic) instructions
- Guarded assignment
- c ? (y1, )(e1, )
36Program state
- State of a program
- Control variables Data variables
- Control variable ?i Pointing to the current
location in process Pi - Each ?i ranges over Li, the set of locations
belonging to Pi
37Diagrams as Basic Transition Systems
- A basic transition system is a quadruple
- State variables
- States
- Transition
- Initial condition
38Diagram elements
- State variables
- All the data and control variables
- ? ?1, , ?m, y1, , yn
- States
- All the possible interpretations that assign to
the state variables values over their respective
domains. - Domain of control variable ?i is the set of
locations Li
39Diagram elements
- Transition
- Idling transition ?i is defined by transition
relation ?i T - Diligent transitions labeled edges that appear
within the processes.
40Example
C ? yi ei
l
l
?
- is the edge.
- ?? (?i l) ? c ? (?il) ? (yi ei)
41Example (cont.)
- Initial condition
- Program P
- declaration where ?P1 Pm
- Initial condition
- ? ? ? /\i1m (?i loi)
- A process is enabled, or disabled on a state.
42Example Binomial coefficient
r4 (y2gtk)?
r0 (y2k)?
r1 ((y1y2)n)?
r2 b b div y2
r3 y2 y21
43- in k, n integer where 0?k?n
- local y1,y2 integer where y1n ? y21
- out b integer where b 1
r4 (y2gtk)?
r0 (y2k)?
r1 ((y1y2)n)?
r2 b b div y2
r3 y2 y21
44A process-deterministic program
- If every two guards c1 and c2 that label two
edges departing from the same location are
exclusive c1 and c2 is never true. - In a process-deterministic program, each process
has at most one transition that is enabled on any
state. - The computation is still not uniquely determined
(several enabled transitions on a given state
from different processes ).
45Representing Concurrency by Interleaving
Reduction of concurrency to nondeterminism
X0,Y0
X0,Y0
Y1
X1
X1
Y1
X1
Y1
Process P1
Process P2
Program B
Program A
46Scheduling
- The choice of the enabled transition to be
executed next. - A sequence of choices that leads to a complete
computation is called a schedule.
47- The only restriction a schedule must obey is that
as long as some process is enabled, some process
must eventually be activated (implied by
diligence requirement). - Diligence either the sequence (computation)
contains infinitely many diligent steps or it
contains terminal state - Excluding sequences in which even though some
diligent transition is enabled, only idling steps
are taken from some point.
48