Unifying Theories Execution History Tony Hoare In honour of Manfred Broy 30 October 2009
Manfred Broy and Tony Hoare at Marktoberdorf.
Unifying… Memory – shared/private, weakly/strongly consistent Communication – synchronised/buffered, reliable/unreliable Resource management – dynamic/nested, disposed/collected
Unifying… Sequential programming – C, Java, C#,... Process algebras and calculi – stream processing functions – CCS, CSP, pi Shared memory, threads – fine-grained, coarse-grained, transactions – weakly consistent memory
Labelled graphs Trace semantics(Mazurkiewicz) Regular expressions(Kleene) Causal nets(Petri) Event structure configurations(Winskel) Message Sequence Charts(UML) INSIGHT! They are all labeled graphs
A labeled Graph E: a set of nodes (events) A: a set of arrows (denoting data flow) L: a set of labels (to be determined) source, target: A -> E label: A -> L (labelling the arrow) label: E -> L (labelling the events)
Program Execution is recorded as a trace of all events that have occurred – drawn as boxes all dependencies between them – drawn as arrows source target – the target could not occur before source
Program Execution is recorded as a trace of: all events that have occurred – drawn as boxes – with labels naming the executed command all dependencies between them – drawn as arrows source target – with labels naming resource.value, etc. x := 3 x.3 x := 3x = 3
A Sequential Resource begin end next
Implementation begin end next allocated globally/on stack/in heap/… disposed from stack/by command/by collector/by OS
Fork fanout all arrows of the graph have the same source
Join fanin all arrows of the graph have the same target
Shared Resource faninfanout begin end
Publication faninfanout publish next
Assignment fanin fanout := 3 := 7 next =3
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
A variable begin end next := fanin fanout = = ==
Unassigned fetch begin end next := fanin fanout fanin fanout
Communication !!! ? ?? send
Ordering next !!! ? ?? send
Channel next !!! ? ?? end begin next send
Single-buffered Channel next !!! ? ?? end begin next send sync
Synchronised next !!! ? ?? end begin next send sync
Lossy channel next !!! ? ? send
Stuttering channel next !! ? ?? send
Fraudulent channel next !! ? ?? send
Overtaking next !! ?? send
Reliable channel reliable = loss & fraud & stutter & merge & overtaking
Threads fork begin end next begin next join begin next end fork join
An Atomic Assignment x := x + y x = 3 y= 4 x := 7
An Atomic Assignment x := x + y x = 3 y= 4 x := 7 x.fanout.3x.fanin y.fanout.4 y.fanin x.next x.fanout.7 x.fanin t.next
An Atomic Assignment x := x + y x = 3 y= 4 x := 7 x.fanout.3x.fanin y.fanout.4 y.fanin x.next x.fanout.7 x.fanin t.next
Events and atomic actions Each occurrence of an event in the trace of program execution belongs to the trace of exactly one resource (thread, variable, channel,…) Atomic actions are groups of synchronised events, including exactly one from the thread which invoked the action, and one (or more) from every resource used by it.
v.fanout v:= 4 v := 3v:= 6 v.next v.fanin v.fanout v.fanin =3 = 4= 6 v.next A variable (fully labelled) v.fanout
t.next v:= 4 v := 3v:= 6 thread t interfering thread v.next =3 = 4= 6 v.next A shared variable v.next
Weakly consistent memory as implemented in multi-core architecture, is even more complicated to define … and more still to use! A common architecture is TSO
Total Store Ordering :=4 sync :=3 :=6global memory sync
Local memory next val next :=4 sync :=3 :=6 := 4:= 3:= 6 local memory global memory sync
Local memory access next val next :=4 sync :=3 :=6 := 4:= 3:= 6 local memory global memory = 3= 4= 6 local memory sync
next val next :=4 sync :=3 :=6 := 4:= 3:= 6 local memory global memory other thread :=4 = 3= 4= 6 local memory sync :=3
Memory Barrier next val next sync :=4 :=3 :=6 := 4:= 3:= 6bar local memory global memory
Summary Dependency and data flow are a primitive concepts adequate to describe the dynamic behaviour of many kinds of computing resource Labelled graphs provide a general framework adequate for a unifying theory of dependency