880 likes | 1k Views
Charts and nets: States, Messages, and Events. Tony Hoare In honour of David Harel Vienna July 2014. Events basic actions and method calls that occur during execution of a program. Event labels basic actions and method calls that occur in the text of the program. x := 9. c ! 9. c ? 9.
E N D
Charts and nets:States, Messages, and Events Tony Hoare In honour of David Harel Vienna July 2014
Eventsbasic actions and method callsthat occur during execution of a program
Event labelsbasic actions and method callsthat occur in the text of the program x := 9 c ! 9 c ? 9
Space and Time where and when an event occurs space time
Spatial Boundaries horizontal, separating concurrent activities space time
Temporal Boundaries vertical, separating sequential activities space time
Dependencies an event at the head of an arrow depends on the event at the tail
Rules for arrows • do not cross a time-boundary backwards • Local arrows are drawn horizontal • They must not cross space boundaries • Non-local arrows are not horizontal • They must not close a cycle.
Object values 9 3 7 x 4 7 7 9 0 y
Object values 9 3 7 x 4 7 7 9 0 y
Message identifiers c! c[25] c[26] c?
The State of Memory • is a map from the identifier of each line which crosses a given temporal boundary to the value which labels the crossing arrow.
State of memory { x = 9, y = 0} 9 x 0 y
Concurrent object behaviour. • A trace of behaviour of an object is an event chart, containing all the events in which it has engaged, connected by dependency arrows. • A class is the set of all possible traces of objects of the class (and related objects.
A local object boxes represent actions of the object arrows connect successive actions
A local object the red arrows connect actions in the same thread protected from interference by other threads
A shared object blue arrows connect actions which may occur in a different threads (or they may occur in the same thread).
An exclusion semaphore is released by the same thread that most recently acquired it. A released semaphore may be acquired by any thread.
with labels enter enter exit exit The boxes are labelled to indicate the nature of the actions: enter or exit
Object allocation alloc has one red output arrow and no red input arrow
Object disposal disp has one red input arrow and no red output arrow
A Communication channel single input port and single output port
A shared output port allows multiple outputting threads
with labels to indicate that the value communicated is the same at both ends of the channel dispose !3 !7 alloc ad =7 =3 ?7 disp ?3 alloc
with a single buffer which is passed back to outputter for refilling !3 disp !7 alloc ad =7 =3 ?7 disp ?3 alloc
a synchronous channel no buffering at all. input and output are simultaneous !3 disp !7 alloc ad =7 =3 ?7 disp ?3 alloc
a re-ordering channel… allows crossing of arrows !3 disp !7 alloc ad =7 =3 ?3 disp ?7 alloc
…with loss of message !7 disp !3 alloc ad =7 disp ?7 alloc
Diagrams in Debugging • display a trace of concurrent execution • with slices for selected objects • keyed to the text of the program • with dependencies to show sources of error • and consequences of its correction.
A program (or an object class) denotes the set of all possible diagrams of execution, on any computer system running in any environment. Programs
Spatial Boundaries horizontal, separating concurrent activities space time
Temporal Boundaries vertical, separating sequential activities space time
Concurrent Composition of event charts p, q, r p q r (p ‖ q)‖ r = p ‖ (q ‖ r)
Sequential composition p q r (p ; q) ; r = p ; (q ; r)
Rules for arrows • do not cross a time-boundary backwards • Local arrows are drawn horizontal • They must not cross space boundaries • Non-local arrows are not horizontal • They must not close a cycle.
Top T • stands for a trace with programming error • T;p = p;T = p||T otherwise…..
Operators • p;q splits the trace across time, into parts that can be executed at different instants. • p∥q splits it across space, into parts that can be executed in different places. • I describes doing nothing
Sequential Composition • p;q = p+q if q x p contained in neg(dep*) • p||q = p+q if p x q contained in neg(red u conv(red)) n neg(dep* n conv(dep*)) } = T otherwise • I = { }
Refinement ≼ • ≼ is a partial order • Covariance: p ≼ q implies • p;r ≼ q;r • r;p ≼ r;q • p∥r ≼ q∥r
Exchange Axiom(p∥q) ; (p’∥q’) ≼ (p;p’) ∥ (q;q’) ; p p’ p p’ ; ≼ ; q q q’ q’ note the self-duality of the law
p ≼ q means that p and q perform all the same actions, but p performs more pairs of them sequentially, and q performs more pairs concurrently. As a result,… • p is more determinate, q is more abstract
Interleaving • (p∥q) ; (p’∥q’) ≼ (p;p’) ∥ (q;q’) • LHS is an interleaving implementation of the more general concurrency of RHS • It is the special case when the two RHS ‘;’s happen to be simultaneous
Frame Laws • (p∥q) ; (p’∥q’) ≼ (p;p’) ∥ (q;q’) • Theorems (frame): • (p∥q) ; q’ ≼ p∥(q;q’) • p;(p’∥q’) ≼ (p;p’)∥q’ • p;q’ ≼ p∥q’ and q;p’ ≼ p’∥q Proof: substitute for variables of the axiom that are omitted in the theorem
Example abcd∥ xyzw (a;bcd) ∥ (xy;zw) (a∥xy) ; (bcd∥zw) (a∥x;y) ; (b;cd∥zw) (a∥x);y ; (b∥zw) ; cd xayzbwcd
A Program • is the set of all traces that it can evoke when executed on any computer system and in any interacting environment. P;Q = {p;q | p e P & q e Q } P||Q = {p||q | p e P & q e Q } P < Q = all p e P . exists q e Q . p < q All our laws for ; and || are preserved for sets