Basic operational semantics for concurrency
Basic domains:
Expressions and commands
Programs
P : Tid → \rightarrow → Cmd, written as P = c 1 c_1 c1 || … || c N c_N cN
Thread subsystem
- Thread-local steps: c,s → l \stackrel{l}{\rightarrow} →l c’, s’
- Interpret sequential programs
- Lift them to program steps: P, S → i : l \stackrel{i:l}{\rightarrow} →i:l P’, S’
Storage subsystem (defined by the memory model)
- Describe the effect of memory accesses and fences
- M → i : l \stackrel{i : l}{\rightarrow} →i:l M’ is the state of storage subsystem
Linking the two
- Either the thread or the storage subsystem make an internal step, ε \varepsilon ε; or they make matching i : l steps
- P,S,M ⇒ \Rightarrow ⇒ P’, S’, M’
The thread subsystem
Store: s : Reg → \rightarrow → Val (Initial store: s 0 = △ λ r . 0 s_0 \stackrel{\triangle}{=} \lambda_r.0 s0=△λr.0 )
State: <c,s> ∈ \in ∈ Command x Store
Transitions:
The thread subsystem: RMW and fence commands
Lifting to concurrent programs
State: ⟨ P , S ⟩ ∈ P r o g r a m × ( T i d → S t o r e ) \langle P, S \rangle \in Program \times (Tid \rightarrow Store) ⟨P,S⟩∈Program×(Tid→Store)
- Initial stores: S 0 = △ λ i . s 0 S_0 \stackrel{\triangle}{=} \lambda_i . s_0 S0=△λi.s0
- Initial state: ⟨ P , S 0 ⟩ \langle P, S_0 \rangle ⟨P,S0⟩
Transition:
P ( i ) , S ( i ) → l c , s P , S → i : l P [ i ↦ c ] , S [ i ↦ s ] \dfrac{P(i), S(i) \stackrel{l}{\rightarrow} c,s}{P,S \stackrel{i:l}{\rightarrow} P[i\mapsto c],S[i\mapsto s]} P,S→i:lP[i↦c],S[i↦s]P(i),S(i)→lc,s
SC storage subsystem
Machine state: M : Loc → \rightarrow → Val
-
Maps each location to its value
-
Initial state: M 0 = △ λ X . 0 M_0 \stackrel{\triangle}{=} \lambda_X . 0 M0=△λX.0
i.e., the memory that maps every location to 0
TSO storage subsystem
The state consists of:
-
A memory M: Loc → \rightarrow → Val
-
A function B: Tid → \rightarrow → (Loc x Val)*
assigning a store buffer to every thread.
**Initial state: ** ⟨ M 0 , B 0 ⟩ \langle M_0, B_0 \rangle ⟨M0,B0⟩ where
- M 0 M_0 M0 = λ X . 0 = \lambda_X.0 =λX.0 (the memory maps 0 to every location)
- B 0 = λ i . ϵ B_0 = \lambda_i.{\epsilon} B0=λi.ϵ (all store buffers are empty)
TSO storage subsystem transitions
TSO: linking thread and storage subsystems
Definition (Allowed outcome)
An outcome O is allowed for a program P under TSO if there exist M such that P P P, S 0 S_0 S0, M 0 M_0 M0, B 0 ⇒ ∗ B_0 \Rightarrow^* B0⇒∗ skip || … || skip , O , M , B 0 O,M,B_0 O,M,B0