Unifying Theories Execution History Tony Hoare In honour of Manfred Broy 30 October 2009
Dec 22, 2015
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.3x := 3 x = 3
Implementation
begin endnextnextnext next
•allocated globally/on stack/in heap/…
•disposed from stack/by command/by collector/by OS
Single-buffered Channel
nextnextnext
nextnextnext
! ! !
? ? ?
endbegin
next
nextsend send send
sync sync
An Atomic Assignment
x := x + y
x = 3
y= 4
x := 7
x.fanout.3 x.fanin
y.fanout.4 y.fanin
x.next x.next
x.fanout.7x.fanin
t.next t.next
An Atomic Assignment
x := x + y
x = 3
y= 4
x := 7
x.fanout.3 x.fanin
y.fanout.4 y.fanin
x.next x.next
x.fanout.7x.fanin
t.next 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 := 3 v:= 6
v.next
v.faninv.fanout
v.fanin
=3 = 4 = 6
v.next
v.next
v.next
A variable (fully labelled)
v.fanout
t.nextt.next
v:= 4
v := 3 v:= 6 thread t
interfering thread
v.next
=3 = 4 = 6
v.next
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
Local memory access
nextnext
val
next
:=4
sync
:=3 :=6
:= 4:= 3 := 6 local memory
global memory
= 3 = 4 = 6local memory
sync
nextnext
val
next
:=4
sync
:=3 :=6
:= 4:= 3 := 6 local memory
global memory
other thread:=4
= 3 = 4 = 6local memory
sync
sync
:=3