Unifying Theories Execution History Tony Hoare In honour of Manfred Broy 30 October 2009.

48
Unifying Theories Execution History Tony Hoare In honour of Manfred Broy 30 October 2009
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    0

Transcript of Unifying Theories Execution History Tony Hoare In honour of Manfred Broy 30 October 2009.

Unifying Theories Execution History

Tony Hoare

In honour of Manfred Broy30 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.3x := 3 x = 3

A Sequential Resource

begin endnextnextnext next

Implementation

begin endnextnextnext next

•allocated globally/on stack/in heap/…

•disposed from stack/by command/by collector/by OS

Fork

fanout

all arrows of the graphhave the same source

Join

fanin

all arrows of the graph have the same target

Shared Resource

faninfanout

begin end

Publication

faninfanout

publish publish next

Assignment

faninfanout

:= 3 := 7next

=3

=3

=3

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

A variable

begin end

nextnextnext next:= := :=

fanin faninfanoutfanout =

=

= =

Unassigned fetch

begin end

nextnextnext next:= := :=

fanin

fanin

fanout fanout faninfanout

Communication

! ! !

? ? ?

send send send

Ordering

nextnext

nextnext

! ! !

? ? ?

send send send

Channel

nextnextnext

nextnextnext

! ! !

? ? ?

endbegin

next

next

send send send

Single-buffered Channel

nextnextnext

nextnextnext

! ! !

? ? ?

endbegin

next

nextsend send send

sync sync

Synchronised

nextnextnext

nextnextnext

! ! !

? ? ?

endbegin

next

nextsend send send

sync sync sync

Lossy channel

nextnext

next

! ! !

? ?

send send

Stuttering channel

next

nextnext

! !

? ? ?

send send send

Fraudulent channel

next

nextnext

! !

? ? ?

send send

Overtaking

next

next

! !

? ?

sendsend

Reliable channel

• reliable = loss & fraud & stutter & merge & overtaking

Threads

forkbegin endnextnextnext next

beginnextnext

joinbeginnextnextnext 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.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

Total Store Ordering

:=4

sync

:=3 :=6 global memory

sync

Local memory

nextnext

val

next

:=4

sync

:=3 :=6

:= 4:= 3 := 6 local memory

global memory

sync

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

Memory Barrier

nextnext

val

next

sync

:=4 :=3 :=6

:= 4:= 3 := 6 bar localmemory

globalmemory

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 frameworkadequate for a unifying theory of dependency