Declarative semantics for concurrency
An alternative way of defining the semantics
Declarative/axiomatic concurrency semantics
- Define the notion of a program execution (generalization of an execution trace)
- Map a program to a set of execution
- Define a consistency predicate on executions
- Semantics = set of consistent executions of a program
Exception: “catch-fire” semantics
Existence of at least one “bad” consistent execution implies undefined behavior
Executions
Events
- Reads, Writes, Updates, Fences
Relations
- Program order, po
- Reads-from, rf
Definition (Label)
A label has one of the following forms:
R x vr W x vw U(x,vr,vw)
where x ∈ \in ∈ Loc and vr, vw ∈ \in ∈ Val
Definition (Event)
An event is a triple <id,i,l> where
id ∈ \in ∈ N is an event identifier
i ∈ \in ∈ Tid ∪ \cup ∪ {0} is a thread identifier, and
l is a label
Definition (Execution graph)
An execution graph is a tuple ⟨ E , p o , r f ⟩ \langle E, po, rf \rangle ⟨E,po,rf⟩ where:
- E is a finite set of events
- po is a partial order on E
- rf is a binary relation on E such that
- For every ⟨ \langle ⟨w,r ⟩ \rangle ⟩ ∈ \in ∈ rf
- typ(w) ∈ \in ∈ {W,U}
- typ® ∈ \in ∈ {R,U}
- loc(w) ∈ \in ∈ loc®
- val w _w w(w) = val r _r r®
- rf − 1 ^{-1} −1 is a function
- that is if ⟨ \langle ⟨w 1 _1 1,r ⟩ \rangle ⟩, ⟨ \langle ⟨w 2 _2 2,r ⟩ \rangle ⟩ ∈ \in ∈ rf, then w 1 _1 1 = w 2 _2 2 )
Some notations
Let G = ⟨ E , p o , r f ⟩ G = \langle E,po, rf \rangle G=⟨E,po,rf⟩ be an execution graph
- G . E = △ E G_{.E} \stackrel{\triangle}{=} E G.E=△E
- $G.po \stackrel{\triangle}{=} po $
- G . r f = △ r f G.rf \stackrel{\triangle}{=} rf G.rf=△rf
- G . R = △ { r ∈ E ∣ t y p ( r ) = R ∨ t y p ( r ) = U } G_{.R} \stackrel{\triangle}{=} \{r \in E | typ(r) = R \vee typ(r) = U\} G.R=△{r∈E∣typ(r)=R∨typ(r)=U}
Mapping programs to executions: Example
Definition
An execution graph G is called sequential if the following hold:
- tid(a) = 0 for every a ∈ \in ∈ G.E
- G.po is a total order on G.E
- G.rf = ∅ \empty ∅
From commands to sequential execution graphs
SILENT
c , s → ε c ′ , s ′ c , s , G ⇒ c ′ , s ′ , G ′ \dfrac{c,s \stackrel{\varepsilon}\rightarrow c',s'}{c,s,G \Rightarrow c',s',G'} c,s,G⇒c′,s′,G′c,s→εc′,s′
NOT-SILENT
c , s → ε c ′ , s ′ l ≠ ϵ a = ⟨ n , 0 , l ⟩ n ∉ { i d ( b ) ∣ b ∈ G . E } c , s , G ⇒ c ′ , s ′ , A d d ( G , a ) \dfrac{c,s \stackrel{\varepsilon}\rightarrow c',s' \; \; l \ne \epsilon \; \; a = \lang n,0,l \rang \; \; n \notin \{ id(b) | b \in G.E \} \; }{c,s,G \Rightarrow c',s',Add(G,a)} c,s,G⇒c′,s′,Add(G,a)c,s→εc′,s′l=ϵa=⟨n,0,l⟩n∈/{id(b)∣b∈G.E}
when Add(G,a) is the execution graph G’ given by:
- G’.E = G.E ∪ + \cup_+ ∪+ {a}
- G’.po = G.po ∪ \cup ∪ (G.E x {a})
- G’.rf = G.rf
Definition (Execution graph of a command) 一个命令的执行图
G is an execution graph of a command c with a final store s if c, s 0 _0 0, G ∅ ⇒ ∗ s k i p , s , G _{\emptyset} \Rightarrow^* skip,s,G ∅⇒∗skip,s,G
Definition (Thread restriction)
给定一个线程Tidh和一个执行图G,G i ^i i 表示通过限制G为事件而获取的顺序执行图,修改他们的线程描述符为0,丢弃rf边
Definition (Execution graph of a program)
G是程序P的执行图(结果为O),如果G i ^i i是P(i)的执行图,对于每个Tid i _i i
Consistency predicate
Definition (Allowed outcome under a declarative model)
An outcome O is allowed for a program P under X if there exists an execution graph G such that:
- G is an execution graph of P with outcome O
- G is X-consistent
Exception: “catch-fire” semantics
… 或若存在一个执行图G,满足:
- G 是P的执行图
- G 是X-一致
- G is bad
Completeness
Definition (Completeness)
一个执行图被称为完整的当
condom(G.rf) =G.R
也就是说,每一个读操作都读取自写操作
Sequential consistency 顺序一致性
Definition
sc是G.E上的一个全序,G被称为顺序一致的,即sc,当
- 若 ⟨ a , b ⟩ ∈ G . p o \lang a,b\rang \in G.po ⟨a,b⟩∈G.po ,则 ⟨ a , b ⟩ ∈ s c \lang a,b \rang \in sc ⟨a,b⟩∈sc
- 若 ⟨ a , b ⟩ ∈ G . r f \lang a,b \rang \in G.rf ⟨a,b⟩∈G.rf ,则 ⟨ a , b , ⟩ ∈ s c \lang a,b, \rang \in sc ⟨a,b,⟩∈sc,rf中间不存在另一个写操作
Definiton
一个执行图被称为顺序一致的,当
G是完全的
G是顺序一致的
Sequential consistency (交错语义定下的顺序一致性)
简而言之,即无环
上述两种定义是等价的!!!