Introduction
Sequential Consistency (SC) is the standard view of communication in concurrency, whereby a thread’s modification of shared memory is immediately visible to the whole system [46 ] . This allows program executions to admit a simple, sequential representation, that reflects the mental model of most practitioners in concurrent programming. In practice, however, interthread communication is considerably more involved, owing to compiler optimizations as well as architectural features such as buffers, caches, and speculative execution. These features can cause threads to hold divergent views of the shared memory, and produce highly complex and counterintuitive weak behaviors . Memory models [6 ] are formal specifications of the behaviors that a program may exhibit in such a system, and have become standard in programming (e.g., for C/C++ [15 ] , Java [48 ] , Rust [67 ] , OCaml [32 ] , the Linux Kernel [8 ] ) and hardware design (e.g., SPARC/x86-TSO [63 ] , Arm [56 ] ).
One desirable property of a program P executing under a memory model M M MM M M is robustness , which specifies that P does not exhibit any weak behaviors under M M MM M M [19 , 64 ] . A robust program, thus, runs with the efficiency of the optimizations allowed by M M MM M M , while following the simple mental and reasoning model of SC. Robust programs further admit SC-based verification techniques, which are far more efficient and lightweight, as typically verification under weak memory is of much higher complexity [12 , 42 ] , or even undecidable [1 , 12 , 23 ] .
Authors’ Contact Information: Giovanna Kobus Conrado, Aarhus University, Aarhus, Denmark, gkc@cs.au.dk; Stephan Spengler, Uppsala University, Uppsala, Sweden, stephan.spengler@it.uu.se; Mohamed Faouzi Atig, Uppsala University, Uppsala, Sweden, mohamed.faouzi.atig@it.uu.se; Andreas Pavlogiannis, Aarhus University, Aarhus, Denmark, pavlogiannnis@cs.au.dk. As such, algorithmically deciding whether a program is robust against a memory model has been studied extensively across many models. Case after case, the problem was proven to be decidable in PSPACE for TSO [18 , 19 ] , PSO [29 ] , RMO [29 ] , POWER [30 ] , RA [44 ] , and a C11-style model [50 ] . Analogous results for transactional models further imply a PSPACE bound for the RMW-free fragments of SRA and WRA [14 ] . At this point, it is natural to ask whether each case indeed requires individual treatment, or they all fall under the umbrella of a single, root argument. Is there a unifying theory for weak-memory robustness?
Our contributions. This paper answers this question affirmatively for a broad class of memory models. Our starting point is Kater [37 ] , which observes that most popular memory models are expressible in Kozen’s Kleene Algebra with Tests (KAT) [40 ] . We show that KAT-definability suffices to decide the robustness question uniformly and, complexity-wise, optimally, under a natural prefix-closedness condition. We summarize here our main contributions, while we refer to the coming sections for formal definitions and proofs.
We consider program executions represented as standard execution graphs [13 , 45 ] G = ⟨ E , s b , r f , m b ⟩ G = \langle E, \mathrm{sb}, \mathrm{rf}, \mathrm{mb} \rangle G = ⟨ E , sb , rf , mb ⟩ , where E E E is a set of events comprising the execution, sb represents the execution order of each thread, rf is a reads-from relation pairing reading events with the writes they observe, and mb represents the order in which writes modify the shared memory. Our primary result is a unifying metatheorem for weak-memory robustness, which we have also formalized in Lean1 .
Theorem 1.1. Given any concurrent program P and any prefix-closed memory model MM defined in KAT, deciding whether P is robust against MM is in PSPACE.
Prefix-closedness is the natural property that the execution of any program can be constructed incrementally as the program runs, and is satisfied by most common memory models. Theorem 1.1 unifies the PSPACE robustness of nearly all prior work2 , and extends the results for SRA and WRA from their RMW-free fragments to the full models. Moreover, it proves that robustness is in PSPACE for several new memory models, e.g., the full RC11 [45 ] , the OCaml memory model [32 ] , LRA [65 ] , and PSI [58 ] (in its shared-memory realization with unary transactions)3 . This closes all memory models that were left open in [44 ] (with PSI restricted to unary transactions). We further remark that robustness is at least as hard as state reachability under SC, against any memory model that can simulate SC (which is often easy, e.g., by utilizing CAS operations or memory fences [9 ] ). In such cases, robustness becomes PSPACE-hard, and thus Theorem 1.1 is tight.
We prove Theorem 1.1 by showing that non-robust programs always contain a regular set of weak executions that can be represented efficiently. This follows the high-level approach of Courcelle’s celebrated work on MSO for graphs [26 ] ; however, Courcelle’s theorem gives a much larger, non-elementary complexity bound. To arrive at PSPACE, we first prove that SC-consistent executions have bounded pathwidth. This, together with the prefix-closedness of MM, implies that non-robust programs always exhibit weak executions of bounded pathwidth. Thus, the search for a witness reduces to searching for a bounded-pathwidth execution of P that is MM-consistent and SC-inconsistent. To perform this search, we define an algebra of graph operations, so that a finite sequence of such operations represents the path decomposition of an execution. We then develop dedicated automata for verifying that such an execution constitutes a robustness violation witness, i.e., that it is (i) valid for P, (ii) MM-consistent, and (iii) SC-inconsistent. Crucially, we ensure that each automaton transition can be verified in polynomial space, leading to our PSPACE bound.
Our automata-theoretic treatment further implies that robustness is always efficiently monitorable in a dynamic setting, e.g., in the spirit of the tool Sober for TSO [20 ] , or the recent Rsan for a C11-style model [49 ] . Thus, although such tools rest on clever insights and memory-model specific optimizations to be efficient, their existence also follows from a unifying algorithmic principle.
Although the prefix-closedness condition of Theorem 1.1 is satisfied by most common memory models, it is not universal. E.g., the, KAT-definable, Relaxed model is not prefix-closed. It is, thus, natural to ask whether this condition is necessary. We prove that it cannot be dropped, in general.
Theorem 1.2. Robustness against Relaxed is undecidable, already over programs with two threads and four memory locations.
Finally, we implement the algorithm behind Theorem 1.1 in a prototype tool RoboKAT, which is parametric on the memory model. We use RoboKAT to check robustness against nine memory models, including RC11, OCaml, SRA and PSI, for which, to our knowledge, no sound and complete robustness checker existed. Although its generality comes at a natural performance cost compared to model-specific tools, RoboKAT gives the correct verdict on each of 180 litmus test/model pairs within seconds, and finds all known violations in the Rocker benchmarks [44 ] .
Preliminaries
In this section, we fix notation and recall automata, introduce execution graphs, programs, and memory models, and define robustness, the main subject of this work.
Background
General notation. Given an integer i i i , we let [ i ] = { 1 , … , i } [i] = \{1, \ldots, i\} [ i ] = { 1 , … , i } . For a binary relation R R R , we write R ? R^{?} R ? , R + R^{+} R + , R ∗ R^{*} R ∗ , and R − 1 R^{-1} R − 1 for its reflexive, transitive, and reflexive-transitive closures and its inverse, respectively. We denote by R 1 ; R 2 R_{1}; R_{2} R 1 ; R 2 the composition of R 1 R_{1} R 1 and R 2 R_{2} R 2 . We write irr ( R ) \operatorname{irr}(R) irr ( R ) , acy ( R ) \operatorname{acy}(R) acy ( R ) , and emp ( R ) \operatorname{emp}(R) emp ( R ) to indicate that R R R is irreflexive, acyclic, and empty, respectively. We occasionally call ⟨ e 1 , e 2 ⟩ ∈ R \langle e_{1}, e_{2}\rangle\in R ⟨ e 1 , e 2 ⟩ ∈ R an edge, written e 1 → R e 2 e_{1} \xrightarrow{R} e_{2} e 1 R e 2 . Given a set S S S , we write [ S ] [S] [ S ] for the identity relation on S S S . A binary relation R R R is a successor relation on a finite set X X X if it is the transitive reduction of some total order on X X X .
Labeled transition systems. A labeled transition system (LTS) is a tuple T = ⟨ Q , Σ , Δ , init ⟩ \mathcal{T} = \langle Q, \Sigma, \Delta, \operatorname{init}\rangle T = ⟨ Q , Σ , Δ , init ⟩ , where (i) Q Q Q is a finite set of states, (ii) Σ \Sigma Σ is a finite alphabet, (iii) Δ ⊆ Q × ( Σ ∪ { ϵ } ) × Q \Delta\subseteq Q \times(\Sigma\cup\{\epsilon\}) \times Q Δ ⊆ Q × ( Σ ∪ { ϵ }) × Q is a transition relation, and (iv) init ∈ Q \operatorname{init} \in Q init ∈ Q is the initial state. We write p → α q p \xrightarrow{\alpha} q p α q for ⟨ p , α , q ⟩ ∈ Δ \langle p, \alpha, q\rangle\in\Delta ⟨ p , α , q ⟩ ∈ Δ , and call the transition silent if α = ϵ \alpha= \epsilon α = ϵ . For a transition δ = ⟨ p , α , q ⟩ \delta= \langle p, \alpha, q\rangle δ = ⟨ p , α , q ⟩ , we let src ( δ ) = p \operatorname{src}(\delta) = p src ( δ ) = p , tgt ( δ ) = q \operatorname{tgt}(\delta) = q tgt ( δ ) = q , and lab ( δ ) = α \operatorname{lab}(\delta) = \alpha lab ( δ ) = α . A run of T \mathcal{T} T is a sequence init → α 1 p 1 → α 2 ⋯ → α n p n \operatorname{init} \xrightarrow{\alpha_{1}} p_{1} \xrightarrow{\alpha_{2}} \cdots\xrightarrow{\alpha_{n}} p_{n} init α 1 p 1 α 2 ⋯ α n p n of transitions starting at init. The language L ( T ) ⊆ Σ ∗ \mathcal{L}(\mathcal{T}) \subseteq\Sigma^{*} L ( T ) ⊆ Σ ∗ contains every word α 1 α 2 ⋯ α n \alpha_{1}\alpha_{2}\cdots\alpha_{n} α 1 α 2 ⋯ α n that induces a run of T \mathcal{T} T . The size of T \mathcal{T} T is ∣ T ∣ = ∣ Q ∣ + ∣ Δ ∣ |\mathcal{T}| = |Q| + |\Delta| ∣ T ∣ = ∣ Q ∣ + ∣Δ∣ .
Word automata. A word automaton is a tuple A = ⟨ Q , Σ , Δ , init , Q F ⟩ \mathcal{A} = \langle Q, \Sigma, \Delta, \operatorname{init}, Q_{F}\rangle A = ⟨ Q , Σ , Δ , init , Q F ⟩ , where ⟨ Q , Σ , Δ , init ⟩ \langle Q, \Sigma, \Delta, \operatorname{init}\rangle ⟨ Q , Σ , Δ , init ⟩ is an LTS and Q F ⊆ Q Q_{F} \subseteq Q Q F ⊆ Q is a set of accepting states. We call a word α 1 α 2 … α n \alpha_{1}\alpha_{2}\ldots\alpha_{n} α 1 α 2 … α n of A \mathcal{A} A if it induces a run in A \mathcal{A} A ending in Q F Q_{F} Q F . A \mathcal{A} A is deterministic if Δ \Delta Δ is a function with no silent transitions.
Execution Graphs
Program domains. We consider concurrent programs consisting of a finite set of threads Tid \operatorname{Tid} Tid . Each thread executes events, and communicates with others through a finite set Loc \operatorname{Loc} Loc of shared locations that store values from a finite set Val \operatorname{Val} Val . Events further carry an annotation from a finite set Ann \operatorname{Ann} Ann .
Labels and events. A label is a read r a ( t , x , v ) r_a(t,x,v) r a ( t , x , v ) , a write w a ( t , x , v ) w_a(t,x,v) w a ( t , x , v ) , a read-modify-write (RMW) r m w a ( t , x , v r , v w ) rmw_a(t,x,v_r,v_w) r m w a ( t , x , v r , v w ) , or a fence f a ( t ) f_a(t) f a ( t ) , where t ∈ T i d t \in\mathrm{Tid} t ∈ Tid is a thread, x ∈ L o c x \in\mathrm{Loc} x ∈ Loc is a location, v v v , v r v_r v r , v w ∈ V a l v_w \in\mathrm{Val} v w ∈ Val are values, and a ∈ A n n a \in\mathrm{Ann} a ∈ Ann is an annotation (e.g., an access mode, such as rlx in RC11). We let Lab be the set of labels. An event e = ⟨ i d , l a b ⟩ e = \langle\mathrm{id}, \mathrm{lab} \rangle e = ⟨ id , lab ⟩ consists of an identifier i d ∈ N \mathrm{id} \in\mathbb{N} id ∈ N and a label l a b ∈ L a b \mathrm{lab} \in\mathrm{Lab} lab ∈ Lab , and E is the set of events. We write l a b ( e ) \mathrm{lab}(e) lab ( e ) , t i d ( e ) \mathrm{tid}(e) tid ( e ) , o p r ( e ) ∈ { r , w , r m w , f } \mathrm{opr}(e) \in\{r,w,rmw,f\} opr ( e ) ∈ { r , w , r m w , f } , and a n n ( e ) \mathrm{ann}(e) ann ( e ) for the label, thread, operation, and annotation of e e e , and l o c ( e ) \mathrm{loc}(e) loc ( e ) , v a l r ( e ) \mathrm{val}_r(e) val r ( e ) , and v a l w ( e ) \mathrm{val}_w(e) val w ( e ) for its location and the values it reads and writes, when defined (e.g., a fence has no location and no value). We use the same notation for labels. We identify events with their labels when identifiers are irrelevant (e.g., w a ( t , x , v ) w_a(t,x,v) w a ( t , x , v ) ), and may further omit components that are irrelevant or clear from the context (e.g., w ( x ) w(x) w ( x ) or f a c q f_{\mathrm{acq}} f acq ). We let R, W, RMW, and F be the sets of read, write, RMW, and fence events, respectively, and use the same names for the corresponding sets of labels. For X ⊆ E X \subseteq E X ⊆ E or X ⊆ L a b X \subseteq\mathrm{Lab} X ⊆ Lab , t ∈ T i d t \in\mathrm{Tid} t ∈ Tid , and x ∈ L o c x \in\mathrm{Loc} x ∈ Loc , we let X t X^t X t and X x X_x X x be the elements of X X X of thread t t t and of location x x x , respectively.
Execution graphs. Under weak memory, program executions are often represented as execution graphs [45 ] , also called candidate executions [13 ] . An execution graph is a tuple G = ⟨ E , s b , r f , m b ⟩ G = \langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb}\rangle G = ⟨ E , sb , rf , mb ⟩ , where E ⊆ E E \subseteq\mathcal{E} E ⊆ E is a finite set of events, and sb, rf, and mb are binary relations over E E E that are well-formed , in the following sense.
The sequenced-before relation sb records the order in which events are issued by each thread, by relating each event to its immediate successor. Formally, sb is well-formed if it is the union of successor relations on E t E^t E t , one per t ∈ T i d t \in\mathrm{Tid} t ∈ Tid .
The reads-from relation rf relates each read/RMW event to the write/RMW event it reads from. Formally, rf is well-formed if r f ⊆ ⋃ x ∈ L o c ( W x ∪ R M W x ) × ( R x ∪ R M W x ) \mathrm{rf} \subseteq\bigcup_{x \in\mathrm{Loc}} (W_x \cup\mathrm{RMW}_x) \times(R_x \cup\mathrm{RMW}_x) rf ⊆ ⋃ x ∈ Loc ( W x ∪ RMW x ) × ( R x ∪ RMW x ) , r f − 1 \mathrm{rf}^{-1} rf − 1 is a function with domain E ∩ ( R ∪ R M W ) E \cap(R \cup\mathrm{RMW}) E ∩ ( R ∪ RMW ) , and v a l w ( e 1 ) = v a l r ( e 2 ) \mathrm{val}_w(e_1) = \mathrm{val}_r(e_2) val w ( e 1 ) = val r ( e 2 ) for each e 1 r f e 2 e_1 \mathrel{\mathrm{rf}} e_2 e 1 rf e 2 .
The modifies-before relation mb orders the writes/RMWs on each location. Formally, mb is well-formed if it is the union of successor relations on E x ∩ ( W ∪ R M W ) E_x \cap(W \cup\mathrm{RMW}) E x ∩ ( W ∪ RMW ) , one per x ∈ L o c x \in\mathrm{Loc} x ∈ Loc .
We write G . E G.E G . E , G . s b G.\mathrm{sb} G . sb , G . r f G.\mathrm{rf} G . rf , and G . m b G.\mathrm{mb} G . mb for the components of G G G , and omit G G G when it is clear from the context. Related literature often defines graphs slightly differently, with p o ≜ s b + \mathrm{po} \triangleq\mathrm{sb}^{+} po ≜ sb + instead of sb and m o ≜ m b + \mathrm{mo} \triangleq\mathrm{mb}^{+} mo ≜ mb + instead of mb, but for our purposes, it is more natural to not consider these relations transitively closed. We call a pair ⟨ E , s b ⟩ \langle E,\mathrm{sb}\rangle ⟨ E , sb ⟩ , i.e., an execution graph without rf and mb, an sb-graph.
Programs
We consider programs given as source code, in a toy language [44 ] with registers, assignments, nondeterministic assignments, conditional branching, and memory operations. Besides the domains Val, Loc, Tid and Ann, each thread t t t has a finite set R e g t \mathrm{Reg}_t Reg t of registers ; these sets are pairwise disjoint, and we let R e g ≜ ⋃ t ∈ T i d R e g t \mathrm{Reg} \triangleq\bigcup_{t \in\mathrm{Tid}} \mathrm{Reg}_t Reg ≜ ⋃ t ∈ Tid Reg t .
Syntax. Expressions Exp and instructions Inst are defined by the following grammar.
E x p ∋ e x p : : = d ∣ v ∣ e x p + e x p ∣ e x p = e x p ∣ e x p ≠ e x p ∣ ⋯ I n s t ∋ i n s t : : = d : = e x p ∣ d : = N D e t ( V a l ′ ) ∣ i f e x p g o t o n ∣ x : = a e x p ∣ d : = a x ∣ d : = a C A S ( x , e x p , e x p ) ∣ f e n c e a \begin{aligned}
\mathrm{Exp} &\ni\mathrm{exp} ::= d \mid v \mid\mathrm{exp} + \mathrm{exp} \mid\mathrm{exp} = \mathrm{exp} \mid\mathrm{exp} \ne\mathrm{exp} \mid\cdots\\
\mathrm{Inst} &\ni\mathrm{inst} ::= d := \mathrm{exp} \mid d := \mathrm{NDet}(\mathrm{Val}^{\prime}) \mid\mathbf{if}\ \mathrm{exp}\ \mathbf{goto}\ n \\
&\qquad\mid x :=_a \mathrm{exp} \mid d :=_a x \mid d :=_a \mathrm{CAS}(x,\mathrm{exp},\mathrm{exp}) \mid\mathrm{fence}_a
\end{aligned} Exp Inst ∋ exp ::= d ∣ v ∣ exp + exp ∣ exp = exp ∣ exp = exp ∣ ⋯ ∋ inst ::= d := exp ∣ d := NDet ( Val ′ ) ∣ if exp goto n ∣ x : = a exp ∣ d : = a x ∣ d : = a CAS ( x , exp , exp ) ∣ fence a
where v ∈ V a l v \in\mathrm{Val} v ∈ Val , V a l ′ ⊆ V a l \mathrm{Val}^{\prime} \subseteq\mathrm{Val} Val ′ ⊆ Val , and d ∈ R e g d \in\mathrm{Reg} d ∈ Reg . We interpret + + + , = = = , ≠ \ne = , and the other binary operators as functions V a l × V a l → V a l \mathrm{Val} \times\mathrm{Val} \to\mathrm{Val} Val × Val → Val , and we assume that Val contains two distinct values 0 and 1, that comparisons such as = = = and ≠ \ne = return 1 if they hold and 0 otherwise, and that if treats 0 as false and every other value as true. The first three instructions are local, with NDet(Val′ ^{\prime} ′ ) representing a nondeterministic choice of a value in Val′ ^{\prime} ′ . The next three instructions access the shared memory, respectively performing a write, read, and compare-and-swap operation on location x x x . The annotation a ∈ A n n a \in\mathrm{Ann} a ∈ Ann may have some impact on the synchronization that these induce, depending on the memory model. Finally, the last instruction is a fence, also carrying an annotation a ∈ A n n a \in\mathrm{Ann} a ∈ Ann . The code of a thread t t t is a finite instruction sequence S t : [ n t ] → I n s t S_t : [n_t] \to\mathrm{Inst} S t : [ n t ] → Inst , where n t n_t n t is the number of instructions of t t t . The thread runs S t ( 1 ) , S t ( 2 ) , … S_t(1), S_t(2), \ldots S t ( 1 ) , S t ( 2 ) , … in order, except that a goto may jump to another line, and it terminates once it leaves [ n t ] [n_t] [ n t ] .
Semantics. Each thread S t S_t S t induces an LTS P s e q t = ⟨ Q t , L a b t , Δ t , i n i t t ⟩ \mathrm{Pseq}_t = \langle Q_t, \mathrm{Lab}_t, \Delta_t, \mathrm{init}_t \rangle Pseq t = ⟨ Q t , Lab t , Δ t , init t ⟩ in the standard way; we give a high-level description here, and refer to Section A.1 for the formal definition.
The states Q t Q_t Q t are pairs ⟨ p c , ϕ ⟩ \langle\mathrm{pc}, \phi\rangle ⟨ pc , ϕ ⟩ of a program counter p c ∈ [ n t + 1 ] \mathrm{pc} \in[n_t+1] pc ∈ [ n t + 1 ] , pointing to the next instruction, where n t + 1 n_t+1 n t + 1 stands for termination and a jump outside [ n t ] [n_t] [ n t ] goes to n t + 1 n_t+1 n t + 1 , and a store ϕ : R e g t → V a l ∪ { ⊥ } \phi: \mathrm{Reg}_t \to\mathrm{Val} \cup\{\bot\} ϕ : Reg t → Val ∪ { ⊥ } , which holds the contents of the registers. Note that ∣ Q t ∣ = ( n t + 1 ) ⋅ ( ∣ V a l ∣ + 1 ) ∣ R e g t ∣ |Q_t| = (n_t+1)\cdot(|\mathrm{Val}|+1)^{|\mathrm{Reg}_t|} ∣ Q t ∣ = ( n t + 1 ) ⋅ ( ∣ Val ∣ + 1 ) ∣ Reg t ∣ . We lift ϕ \phi ϕ to expressions as usual, with ϕ ( e x p ) = ⊥ \phi(\mathrm{exp}) = \bot ϕ ( exp ) = ⊥ whenever exp mentions a register holding ⊥ \bot ⊥ , i.e., an uninitialized register.
The alphabet L a b t \mathrm{Lab}_t Lab t is the set of labels of events of t t t .
The transition relation Δ t \Delta_t Δ t executes the instruction S t ( p c ) S_t(\mathrm{pc}) S t ( pc ) , provided that the expressions it evaluates are not ⊥ \bot ⊥ . Local instructions lead to silent transitions that simply update p c \mathrm{pc} pc and ϕ \phi ϕ . Every other instruction emits the label of the event it executes, e.g., x : = a e x p x :=_a \mathrm{exp} x : = a exp emits w a ( t , x , ϕ ( e x p ) ) w_a(t,x,\phi(\mathrm{exp})) w a ( t , x , ϕ ( exp )) . A read d : = a x d :=_a x d : = a x may emit r a ( t , x , v ) r_a(t,x,v) r a ( t , x , v ) for any v ∈ V a l v \in\mathrm{Val} v ∈ Val , and stores v v v in d d d ; the actual value it observes is fixed later. Likewise, d : = a C A S ( x , e x p R , e x p W ) d :=_a \mathrm{CAS}(x,\mathrm{exp}_{R},\mathrm{exp}_{W}) d : = a CAS ( x , exp R , exp W ) emits an RMW label if it reads ϕ ( e x p R ) \phi(\mathrm{exp}_{R}) ϕ ( exp R ) , and a read label otherwise. To distinguish it from the read of a read instruction, a failed CAS annotates its read label with a dedicated sibling of its annotation.
The initial state i n i t t \mathrm{init}_t init t is ⟨ 1 , ϕ 0 ⟩ \langle1,\phi_0\rangle ⟨ 1 , ϕ 0 ⟩ , where ϕ 0 \phi_0 ϕ 0 maps every register to ⊥ \bot ⊥ .
Concurrent programs. We interchangeably use S t S_t S t and P s e q t \mathrm{Pseq}_t Pseq t to refer to the sequential program of thread t t t ; their distinction will be clear from the context. Likewise, the concurrent program P P P is represented as a collection of sequential programs ⟨ S t ⟩ t ∈ T i d \langle S_t\rangle_{t\in\mathrm{Tid}} ⟨ S t ⟩ t ∈ Tid or their respective LTSs ⟨ P s e q t ⟩ t ∈ T i d \langle\mathrm{Pseq}_t\rangle_{t\in\mathrm{Tid}} ⟨ Pseq t ⟩ t ∈ Tid . Given an sb-graph G = ⟨ E , s b ⟩ G = \langle E,\mathrm{sb}\rangle G = ⟨ E , sb ⟩ and a thread t ∈ T i d t \in\mathrm{Tid} t ∈ Tid , let G ↾ s b ≜ lab ( e 1 ) lab ( e 2 ) … lab ( e n ) G\mathord{\upharpoonright}_{\mathrm{sb}} \triangleq\operatorname{lab}(e_1)\operatorname{lab}(e_2)\ldots\operatorname{lab}(e_n) G ↾ sb ≜ lab ( e 1 ) lab ( e 2 ) … lab ( e n ) , where e 1 , e 2 , … , e n e_1,e_2,\ldots,e_n e 1 , e 2 , … , e n enumerates E E E in sb-order. The graph language of P P P is
G ( P ) ≜ { G : G is an sb-graph and G ↾ s b ∈ L ( P s e q t ) for every t ∈ T i d } . \mathcal{G}(P) \triangleq\{G : G\text{ is an sb-graph and }G\mathord{\upharpoonright}_{\mathrm{sb}} \in\mathcal{L}(\mathrm{Pseq}_t)\text{ for every }t \in\mathrm{Tid}\}. G ( P ) ≜ { G : G is an sb-graph and G ↾ sb ∈ L ( Pseq t ) for every t ∈ Tid } .
the sb-graphs in which each thread executes according to its own sequential program.
Memory Models
A memory model specifies which behaviors a concurrent system may exhibit. In our setting, behaviors are execution graphs, and a model allows those that avoid certain forbidden cycles. Following [37 ] , we express these patterns over Kleene Algebra with Tests (KAT).
Tests. A test is a set of labels τ ⊆ L a b \tau\subseteq\mathrm{Lab} τ ⊆ Lab , and we let T e s t s = 2 L a b \mathrm{Tests} = 2^{\mathrm{Lab}} Tests = 2 Lab be the set of tests. We let G . τ ≜ { e ∈ G . E : lab ( e ) ∈ τ } G.\tau\triangleq\{e \in G.E : \operatorname{lab}(e) \in\tau\} G . τ ≜ { e ∈ G . E : lab ( e ) ∈ τ } be the events of G G G satisfying τ \tau τ , and we write [ τ ] [\tau] [ τ ] for [ G . τ ] [G.\tau] [ G . τ ] . In practice, tests are combinations of equalities on components of a label, such as N \ L a b x N \mathbin{\backslash\!\! \mathrm{Lab}} x N \ Lab x , the writes on x x x , or { l a b ∈ L a b : ann ( l a b ) = r l x } \{\mathrm{lab} \in\mathrm{Lab} : \operatorname{ann}(\mathrm{lab}) = \mathrm{rlx}\} { lab ∈ Lab : ann ( lab ) = rlx } , the labels annotated with rlx. We assume throughout that every test occurring in a memory model is of this form, so lab ∈ τ \operatorname{lab} \in\tau lab ∈ τ can be decided in time polynomial in ∣ T i d ∣ + ∣ L o c ∣ + ∣ V a l ∣ + ∣ A n n ∣ |\mathrm{Tid}| + |\mathrm{Loc}| + |\mathrm{Val}| + |\mathrm{Ann}| ∣ Tid ∣ + ∣ Loc ∣ + ∣ Val ∣ + ∣ Ann ∣ .
KAT expressions. Our relation symbols are R e l ≜ { s b , r f , m b , s b − 1 , r f − 1 , m b − 1 } \mathrm{Rel} \triangleq\{\mathrm{sb},\mathrm{rf},\mathrm{mb},\mathrm{sb}^{-1},\mathrm{rf}^{-1},\mathrm{mb}^{-1}\} Rel ≜ { sb , rf , mb , sb − 1 , rf − 1 , mb − 1 } ; G . b G.b G . b denotes the corresponding relation of G G G . So, the relations of an execution graph (together with their inverses) are the building blocks of memory models. KAT expressions are given by the grammar
φ : : = [ τ ] ∣ b ∣ φ ∪ φ ∣ φ ; φ ∣ φ + ∣ φ − 1 , \varphi::= [\tau] \mid b \mid\varphi\cup\varphi\mid\varphi;\varphi\mid\varphi^{+} \mid\varphi^{-1}, φ ::= [ τ ] ∣ b ∣ φ ∪ φ ∣ φ ; φ ∣ φ + ∣ φ − 1 ,
where τ ∈ T e s t s \tau\in\mathrm{Tests} τ ∈ Tests and b ∈ R e l b \in\mathrm{Rel} b ∈ Rel . An expression φ \varphi φ denotes a binary relation G . φ G.\varphi G . φ over G . E G.E G . E , defined as expected: G . [ τ ] ≜ [ G . τ ] G.[\tau] \triangleq[G.\tau] G . [ τ ] ≜ [ G . τ ] , G . ( φ 1 ∪ φ 2 ) ≜ G . φ 1 ∪ G . φ 2 G.(\varphi_1 \cup\varphi_2) \triangleq G.\varphi_1 \cup G.\varphi_2 G . ( φ 1 ∪ φ 2 ) ≜ G . φ 1 ∪ G . φ 2 , G . ( φ 1 ; φ 2 ) ≜ G . φ 1 ; G . φ 2 G.(\varphi_1;\varphi_2) \triangleq G.\varphi_1;G.\varphi_2 G . ( φ 1 ; φ 2 ) ≜ G . φ 1 ; G . φ 2 , and G . φ + ≜ ( G . φ ) + G.\varphi^{+} \triangleq(G.\varphi)^{+} G . φ + ≜ ( G . φ ) + , and G . φ − 1 ≜ ( G . φ ) − 1 G.\varphi^{-1} \triangleq(G.\varphi)^{-1} G . φ − 1 ≜ ( G . φ ) − 1 . We also write φ ? ≜ φ ∪ [ L a b ] \varphi^{?} \triangleq\varphi\cup[\mathrm{Lab}] φ ? ≜ φ ∪ [ Lab ] and φ ∗ ≜ ( φ + ) ? \varphi^{*} \triangleq(\varphi^{+})^{?} φ ∗ ≜ ( φ + ) ? . The size ∣ φ ∣ |\varphi| ∣ φ ∣ of φ \varphi φ is its number of occurrences of tests, base relation symbols and operators. Compared to [37 ] , we add the inverse operator, and keep tests as sets of labels rather than as Boolean combinations of predicates.
Derived relations. Common relations are abbreviations of KAT expressions, such as p o ≜ s b + \mathrm{po} \triangleq\mathrm{sb}^{+} po ≜ sb + , m o ≜ m b + \mathrm{mo} \triangleq\mathrm{mb}^{+} mo ≜ mb + , h b ≜ ( p o ∪ r f ) + \mathrm{hb} \triangleq(\mathrm{po} \cup\mathrm{rf})^{+} hb ≜ ( po ∪ rf ) + , and r f e ≜ ⋃ t ∈ T i d [ L a b t ] ; r f ; [ L a b ∖ L a b t ] \mathrm{rfe} \triangleq\bigcup_{t \in\mathrm{Tid}} [\mathrm{Lab}^{t}];\mathrm{rf};[\mathrm{Lab} \setminus\mathrm{Lab}^{t}] rfe ≜ ⋃ t ∈ Tid [ Lab t ] ; rf ; [ Lab ∖ Lab t ] . We call such expressions derived relations, and the size of a derived relation is the size of the KAT expression defining it; e.g., r f e \mathrm{rfe} rfe has size O ( ∣ T i d ∣ ) O(|\mathrm{Tid}|) O ( ∣ Tid ∣ ) . The from-read relation is usually defined as f r ≜ ( r f − 1 ; m o ) ∖ i d \mathrm{fr} \triangleq(\mathrm{rf}^{-1};\mathrm{mo}) \setminus\mathrm{id} fr ≜ ( rf − 1 ; mo ) ∖ id , where i d \mathrm{id} id is identity. It relates a read to the writes that are m o \mathrm{mo} mo -after the write it reads from, except itself (e.g., in case it is an RMW). Sensible models that use f r \mathrm{fr} fr also require every RMW to read from its m b \mathrm{mb} mb -predecessor, in which case f r \mathrm{fr} fr is KAT-definable as f r ≜ [ R ] ; r f − 1 ; m o ∪ [ R M W ] ; r f − 1 ; m o ; m o \mathrm{fr} \triangleq[\mathrm{R}];\mathrm{rf}^{-1};\mathrm{mo} \cup[\mathrm{RMW}];\mathrm{rf}^{-1};\mathrm{mo};\mathrm{mo} fr ≜ [ R ] ; rf − 1 ; mo ∪ [ RMW ] ; rf − 1 ; mo ; mo — throughout the paper, we use the latter definition when defining various memory models.
Memory models. A memory model M M \mathrm{MM} MM is a KAT expression. An execution graph G G G is consistent in M M \mathrm{MM} MM , denoted G ⊨ M M G \models\mathrm{MM} G ⊨ MM , if G . M M G.\mathrm{MM} G . MM is irreflexive, and inconsistent in M M \mathrm{MM} MM otherwise. We let ⟦ M M ⟧ = { G : G is an execution graph and G ⊨ M M } \llbracket\mathrm{MM} \rrbracket= \{G : G \text{ is an execution graph and } G \models\mathrm{MM}\} [ [ MM ] ] = { G : G is an execution graph and G ⊨ MM } be the set of M M \mathrm{MM} MM -consistent execution graphs. Some memory models are commonly expressed using several emptiness, acyclicity and irreflexivity conditions, but all these are expressible in our setup: e m p ( φ ) \mathrm{emp}(\varphi) emp ( φ ) is equivalent to i r r ( φ ; φ − 1 ) \mathrm{irr}(\varphi;\varphi^{-1}) irr ( φ ; φ − 1 ) , a c y ( φ ) \mathrm{acy}(\varphi) acy ( φ ) is equivalent to i r r ( φ + ) \mathrm{irr}(\varphi^{+}) irr ( φ + ) , and i r r ( φ 1 ) ∧ i r r ( φ 2 ) \mathrm{irr}(\varphi_{1}) \land\mathrm{irr}(\varphi_{2}) irr ( φ 1 ) ∧ irr ( φ 2 ) is equivalent to i r r ( φ 1 ∪ φ 2 ) \mathrm{irr}(\varphi_{1} \cup\varphi_{2}) irr ( φ 1 ∪ φ 2 ) . For example, the standard Sequential Consistency [46 ] and the fragment of C11 with release/acquire atomics [44 ] are
S C ≜ ( p o ∪ r f ∪ m o ∪ f r ) + and R A ≜ h b ∪ m o ; h b ∪ m o ; h b ; r f − 1 ∪ m o ; m o ; r f − 1 . \begin{aligned}
\mathrm{SC} &\triangleq(\mathrm{po} \cup\mathrm{rf} \cup\mathrm{mo} \cup\mathrm{fr})^{+}
\qquad\text{and}\qquad
\mathrm{RA} \triangleq\mathrm{hb} \cup\mathrm{mo};\mathrm{hb} \cup\mathrm{mo};\mathrm{hb};\mathrm{rf}^{-1} \cup\mathrm{mo};\mathrm{mo};\mathrm{rf}^{-1}.
\end{aligned} SC ≜ ( po ∪ rf ∪ mo ∪ fr ) + and RA ≜ hb ∪ mo ; hb ∪ mo ; hb ; rf − 1 ∪ mo ; mo ; rf − 1 .
In particular for R A \mathrm{RA} RA , the four relations connected under ∪ \cup ∪ are known, in order, as irreflexivity of h b \mathrm{hb} hb , write coherence , read coherence , and atomicity .
Program semantics. Given a memory model M M \mathrm{MM} MM , the semantics of P under M M \mathrm{MM} MM is ⟦ P ⟧ M M ≜ { G ∈ ⟦ M M ⟧ : ⟨ G . E , G . s b ⟩ ∈ G ( P ) } \llbracket P \rrbracket_{\mathrm{MM}} \triangleq\{G \in\llbracket\mathrm{MM} \rrbracket: \langle G.E,G.\mathrm{sb}\rangle\in\mathcal{G}(P)\} [ [ P ] ] MM ≜ { G ∈ [ [ MM ] ] : ⟨ G . E , G . sb ⟩ ∈ G ( P )} , i.e., the execution graphs of P that are consistent in M M \mathrm{MM} MM .
Prefix-closedness. Let G = ⟨ E , s b , r f , m b ⟩ G = \langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb}\rangle G = ⟨ E , sb , rf , mb ⟩ be an execution graph. An event e ∈ E e \in E e ∈ E is maximal in G G G if it has no outgoing s b \mathrm{sb} sb -edge and no outgoing r f \mathrm{rf} rf -edge. For a maximal event e ∈ E e \in E e ∈ E , we write G ∖ { e } G \setminus\{e\} G ∖ { e } for the execution graph induced by E ∖ { e } E \setminus\{e\} E ∖ { e } , i.e., with s b \mathrm{sb} sb and r f \mathrm{rf} rf restricted to E ∖ { e } E \setminus\{e\} E ∖ { e } and m b \mathrm{mb} mb replaced by the transitive reduction of m b + ∩ ( ( E ∖ { e } ) × ( E ∖ { e } ) ) \mathrm{mb}^{+} \cap((E \setminus\{e\}) \times(E \setminus\{e\})) mb + ∩ (( E ∖ { e }) × ( E ∖ { e })) . A memory model M M \mathrm{MM} MM is prefix-closed [38 ] if every non-empty G ⊨ M M G \models\mathrm{MM} G ⊨ MM has a maximal event e e e such that G ∖ { e } ⊨ M M G \setminus\{e\} \models\mathrm{MM} G ∖ { e } ⊨ MM . As a maximal event is the last event of its thread, and the language of an LTS is closed under prefixes, G ∖ { e } G \setminus\{e\} G ∖ { e } is then an execution of every program of which G G G is an execution, i.e., G ∈ ⟦ P ⟧ M M G \in\llbracket P \rrbracket_{\mathrm{MM}} G ∈ [ [ P ] ] MM implies G ∖ { e } ∈ ⟦ P ⟧ M M G \setminus\{e\} \in\llbracket P \rrbracket_{\mathrm{MM}} G ∖ { e } ∈ [ [ P ] ] MM . Intuitively, prefix-closed memory models allow executions to be constructed incrementally. Most common memory models are prefix-closed.
Robustness. We can now define robustness, the main focus of this paper. As standard, SC is the strongest memory model we consider, i.e., for any memory model M M \mathrm{MM} MM , we have ⟦ S C ⟧ ⊆ ⟦ M M ⟧ \llbracket\mathrm{SC} \rrbracket\subseteq\llbracket\mathrm{MM} \rrbracket [ [ SC ] ] ⊆ [ [ MM ] ] . Given additionally a program P, robustness asks whether P exhibits any weak behaviors under M M \mathrm{MM} MM . Formally, P is robust against M M \mathrm{MM} MM iff ⟦ P ⟧ S C = ⟦ P ⟧ M M \llbracket P \rrbracket_{\mathrm{SC}} = \llbracket P \rrbracket_{\mathrm{MM}} [ [ P ] ] SC = [ [ P ] ] MM . A robustness violation witness (or simply witness ) is an execution graph G ∈ ⟦ P ⟧ M M ∖ ⟦ P ⟧ S C G \in\llbracket P \rrbracket_{\mathrm{MM}} \setminus\llbracket P \rrbracket_{\mathrm{SC}} G ∈ [ [ P ] ] MM ∖ [ [ P ] ] SC . Figure 1 shows a non-robust program and a witness.
Figure 1. A non-RA-robust program illustrating store buffering (a), and a witness exhibiting the SC-cycle e 3 → s b e 4 → f r e 5 → s b e 6 → f r e 3 e_3 \mathrel{\xrightarrow{\mathrm{sb}}} e_4 \mathrel{\xrightarrow{\mathrm{fr}}} e_5 \mathrel{\xrightarrow{\mathrm{sb}}} e_6 \mathrel{\xrightarrow{\mathrm{fr}}} e_3 e 3 sb e 4 fr e 5 sb e 6 fr e 3 (b).
KAT Automata
Our algorithm for robustness does not deal with KAT expressions directly. Instead, we compile memory models into nondeterministic automata using standard procedures [41 ] , similarly to [37 ] .
KAT-NFAs. A KAT-NFA is a word automaton K = ⟨ Q , T e s t s ∪ R e l , Δ , i n i t , Q F ⟩ \mathcal{K} = \langle Q,\mathrm{Tests} \cup\mathrm{Rel},\Delta,\mathrm{init},Q_{F}\rangle K = ⟨ Q , Tests ∪ Rel , Δ , init , Q F ⟩ over the alphabet of tests and base relation symbols, such that Δ \Delta Δ has no silent transitions. So, L ( K ) \mathcal{L}(\mathcal{K}) L ( K ) is the set of words l 1 l 2 ⋯ l k l_{1}l_{2}\cdots l_{k} l 1 l 2 ⋯ l k over Tests ∪ \cup ∪ Rel for which there is a run init → l 1 q 1 → l 2 ⋯ → l k q k \xrightarrow{l_{1}} q_{1} \xrightarrow{l_{2}} \cdots\xrightarrow{l_{k}} q_{k} l 1 q 1 l 2 ⋯ l k q k of K \mathcal{K} K with q k ∈ Q F q_{k} \in Q_{F} q k ∈ Q F .
More generally, we say that K \mathcal{K} K has a run on w = l 1 l 2 ⋯ l k w = l_1 l_2 \cdots l_k w = l 1 l 2 ⋯ l k from q q q to q ′ q' q ′ if there are transitions q → l 1 q 1 → l 2 ⋯ → l k q ′ q \xrightarrow{l_1} q_1 \xrightarrow{l_2} \cdots\xrightarrow{l_k} q' q l 1 q 1 l 2 ⋯ l k q ′ in Δ \Delta Δ .
Realizations. Let G G G be an execution graph and w = l 1 l 2 ⋯ l k w = l_1 l_2 \cdots l_k w = l 1 l 2 ⋯ l k a word over Tests ∪ \cup ∪ Rel. A realization of w w w in G G G is a sequence of events e 0 , e 1 , … , e k ∈ G . E e_0, e_1, \ldots, e_k \in G.E e 0 , e 1 , … , e k ∈ G . E such that, for each 1 ≤ i ≤ k 1 \le i \le k 1 ≤ i ≤ k , ⟨ e i − 1 , e i ⟩ ∈ G . l i \langle e_{i-1}, e_i\rangle\in G.l_i ⟨ e i − 1 , e i ⟩ ∈ G . l i if l i ∈ R e l l_i \in\mathrm{Rel} l i ∈ Rel , and e i − 1 = e i ∈ G . l i e_{i-1} = e_i \in G.l_i e i − 1 = e i ∈ G . l i if l i ∈ T e s t s l_i \in\mathrm{Tests} l i ∈ Tests . The realization goes from e 0 e_0 e 0 to e k e_k e k , and it is cyclic if e 0 = e k e_0 = e_k e 0 = e k . So, a realization traverses one edge of G G G at a time, and a test checks the label of the current event.
Compilation. Every KAT expression can be compiled into a KAT-NFA whose words realize exactly the edges of the expression, as captured formally by the following lemma.
Lemma 2.1 ([41 ] ). For every KAT expression φ \varphi φ , there is a KAT-NFA K φ \mathcal{K}_{\varphi} K φ with O ( ∣ φ ∣ ) O(|\varphi|) O ( ∣ φ ∣ ) states and transitions, constructible in time O ( ∣ φ ∣ ) O(|\varphi|) O ( ∣ φ ∣ ) , such that, for every execution graph G G G and e , e ′ ∈ G . E e,e' \in G.E e , e ′ ∈ G . E , we have ⟨ e , e ′ ⟩ ∈ G . φ \langle e,e'\rangle\in G.\varphi ⟨ e , e ′ ⟩ ∈ G . φ iff some w ∈ L ( K φ ) w \in L(\mathcal{K}_{\varphi}) w ∈ L ( K φ ) has a realization in G G G from e e e to e ′ e' e ′ .
We say that a KAT-NFA K \mathcal{K} K is a KAT-NFA for a memory model MM if, for every execution graph G G G , G ⊨ M M G \models\mathrm{MM} G ⊨ MM iff no word of L ( K ) L(\mathcal{K}) L ( K ) has a cyclic realization in G G G . By Lemma 2.1, K M M \mathcal{K}_{\mathrm{MM}} K MM is a KAT-NFA for MM, but MM may have others. Figure 2 illustrates KAT-NFAs for SC and RA on an example.
Figure 2. (a) and (b) show KAT-NFAs for SC and RA. (c) shows the cycle of Figure 1 b that drives (a) from init to the accepting state q 1 q_1 q 1 , so G ⊭ S C G \not\models\mathrm{SC} G ⊨ SC ; each column lists the states at one event, joined by the tests the event satisfies.
The Pathwidth of Execution Graphs
In this section, we present the graph-theoretic notion of pathwidth, and prove the first result towards our Theorem 5.4: against prefix-closed memory models, a non-robust program always exhibits a witness whose pathwidth is bounded in terms of ∣ T i d ∣ |\mathrm{Tid}| ∣ Tid ∣ and ∣ L o c ∣ |\mathrm{Loc}| ∣ Loc ∣ .
Path Decompositions and Pathwidth
Pathwidth is a graph-theoretic notion that measures how closely a graph resembles a path [61 ] .
Path decompositions and pathwidth. Let G = ⟨ E , s b , r f , m b ⟩ G = \langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb}\rangle G = ⟨ E , sb , rf , mb ⟩ be an execution graph, and call e → b e ′ e \xrightarrow{b} e' e b e ′ with b ∈ { s b , r f , m b } b \in\{\mathrm{sb},\mathrm{rf},\mathrm{mb}\} b ∈ { sb , rf , mb } the edges of G G G . A path decomposition of G G G is a sequence X 1 , X 2 , … , X n \mathcal{X}_1,\mathcal{X}_2,\ldots,\mathcal{X}_n X 1 , X 2 , … , X n of subsets of E E E , called bags , such that (i) every event appears in some bag, i.e., ⋃ i ∈ [ n ] X i = E \bigcup_{i \in[n]} \mathcal{X}_i = E ⋃ i ∈ [ n ] X i = E , (ii) every edge appears in some bag, i.e., for every edge e → b e ′ e \xrightarrow{b} e' e b e ′ of G G G there exists some i ∈ [ n ] i \in[n] i ∈ [ n ] with e , e ′ ∈ X i e,e' \in X_i e , e ′ ∈ X i , and (iii) every event appears in a contiguous subsequence of bags, i.e., for all i , j , k ∈ [ n ] i,j,k \in[n] i , j , k ∈ [ n ] with i ≤ j ≤ k i \le j \le k i ≤ j ≤ k , we have X i ∩ X k ⊆ X j X_i \cap X_k \subseteq X_j X i ∩ X k ⊆ X j . The width of a path decomposition is max i ∈ [ n ] ∣ X i ∣ − 1 \max_{i \in[n]} |X_i| - 1 max i ∈ [ n ] ∣ X i ∣ − 1 . The pathwidth of G G G , written pw ( G ) \operatorname{pw}(G) pw ( G ) , is the smallest width among the path decompositions of G G G .
Very nice path decompositions. It is often convenient to work with decompositions that change by one event at a time, and consider one edge at a time. A path decomposition X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X 1 , X 2 , … , X n of G G G is very nice if X 1 = X n = ∅ X_1 = X_n = \emptyset X 1 = X n = ∅ and each bag X i + 1 X_{i+1} X i + 1 , for i ∈ [ n − 1 ] i \in[n-1] i ∈ [ n − 1 ] , can be labeled with one of the following steps, so that the corresponding condition holds.
Introduce e e e , for e ∈ E e \in E e ∈ E : X i + 1 = X i ∪ { e } X_{i+1} = X_i \cup\{e\} X i + 1 = X i ∪ { e } , and e e e appears in no bag X j X_j X j with j ≤ i j \le i j ≤ i .
Forget e e e , for e ∈ E e \in E e ∈ E : X i + 1 = X i ∖ { e } X_{i+1} = X_i \setminus\{e\} X i + 1 = X i ∖ { e } , and e ∈ X i e \in X_i e ∈ X i .
Introduce e → b e ′ e \xrightarrow{b} e' e b e ′ , for an edge e → b e ′ e \xrightarrow{b} e' e b e ′ of G G G : X i + 1 = X i X_{i+1} = X_i X i + 1 = X i , and e , e ′ ∈ X i e,e' \in X_i e , e ′ ∈ X i .
Moreover, every edge is introduced exactly once, i.e., each edge labels exactly one bag.
Lemma 3.1 ([27 ] ). Every execution graph G = ⟨ E , s b , r f , m b ⟩ G = \langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb}\rangle G = ⟨ E , sb , rf , mb ⟩ has a very nice path decomposition of width pw ( G ) \operatorname{pw}(G) pw ( G ) and at most 2 ∣ E ∣ + ∣ s b ∣ + ∣ r f ∣ + ∣ m b ∣ + 1 2|E| + |\mathrm{sb}| + |\mathrm{rf}| + |\mathrm{mb}| + 1 2∣ E ∣ + ∣ sb ∣ + ∣ rf ∣ + ∣ mb ∣ + 1 bags.
Pathwidth and Memory Models
In general, execution graphs of weak memory models have unbounded pathwidth, even without their m b \mathrm{mb} mb -edges [22 ] . The pathwidth of SC-consistent graphs, however, is bounded, and this often suffices to bound the pathwidth of robustness-violation witnesses.
The pathwidth of SC. Let G G G be some SC-consistent execution graph. Recall that G ⊨ S C G \models\mathrm{SC} G ⊨ SC iff ( p o ∪ r f ∪ m o ∪ f r ) + (\mathrm{po} \cup\mathrm{rf} \cup\mathrm{mo} \cup\mathrm{fr})^{+} ( po ∪ rf ∪ mo ∪ fr ) + is irreflexive in G G G . Let σ = e 1 , e 2 , … , e n \sigma= e_1,e_2,\ldots,e_n σ = e 1 , e 2 , … , e n be a linear extension of ( p o ∪ r f ∪ m o ∪ f r ) + (\mathrm{po} \cup\mathrm{rf} \cup\mathrm{mo} \cup\mathrm{fr})^{+} ( po ∪ rf ∪ mo ∪ fr ) + , and write e ≺ e ′ e \prec e' e ≺ e ′ when e e e precedes e ′ e' e ′ in σ \sigma σ . We construct a path decomposition of G G G where the i i i -th bag consists of e i e_i e i together with (i) the ≺ \prec ≺ -largest event of E t ∩ { e 1 , … , e i − 1 } E^t \cap\{e_1,\ldots,e_{i-1}\} E t ∩ { e 1 , … , e i − 1 } , for each t ∈ T i d t \in\mathrm{Tid} t ∈ Tid , and (ii) the ≺ \prec ≺ -largest event of E x ∩ ( W ∪ R M W ) ∩ { e 1 , … , e i − 1 } E_x \cap(W \cup\mathrm{RMW}) \cap\{e_1,\ldots,e_{i-1}\} E x ∩ ( W ∪ RMW ) ∩ { e 1 , … , e i − 1 } , for each x ∈ L o c x \in\mathrm{Loc} x ∈ Loc , whenever these exist. In words, while scanning σ \sigma σ , the bags remember the last event of each thread and the last write/RMW on each location. This covers every s b \mathrm{sb} sb - and m b \mathrm{mb} mb -edge, which joins an event to the previous event of its thread or location, respectively. It also covers every r f \mathrm{rf} rf -edge, since, under SC, every read/RMW observes the latest write/RMW on its location. See Figure 3 .
Figure 3. A graph G G G over T i d = { t 0 , t 1 } \mathrm{Tid}=\{t_0,t_1\} Tid = { t 0 , t 1 } and L o c = { x , y } \mathrm{Loc}=\{x,y\} Loc = { x , y } (a), and a path decomposition of G G G of width 4 (b).
Lemma 3.2. For every execution graph G G G , if G ⊨ S C G \models\mathrm{SC} G ⊨ SC then pw ( G ) ≤ ∣ T i d ∣ + ∣ L o c ∣ \operatorname{pw}(G) \le|\mathrm{Tid}| + |\mathrm{Loc}| pw ( G ) ≤ ∣ Tid ∣ + ∣ Loc ∣ .
Hereinafter, we write pw S C ≜ ∣ T i d ∣ + ∣ L o c ∣ \operatorname{pw}_{\mathrm{SC}} \triangleq|\mathrm{Tid}| + |\mathrm{Loc}| pw SC ≜ ∣ Tid ∣ + ∣ Loc ∣ for the bound of Lemma 3.2.
Pathwidth-bounded witnesses. Given ℓ ∈ N \ell\in\mathbb{N} ℓ ∈ N , a robustness-violation witness G G G is ℓ \ell ℓ -pw-bounded if pw ( G ) ≤ ℓ \operatorname{pw}(G) \le\ell pw ( G ) ≤ ℓ . A memory model M M \mathrm{MM} MM admits ℓ \ell ℓ -pw-bounded witnesses if every concurrent program that is not robust against M M \mathrm{MM} MM has an ℓ \ell ℓ -pw-bounded witness. In such cases, the robustness of a program P P P against M M \mathrm{MM} MM simplifies to searching for a violation over graphs of bounded pathwidth only. The next lemma implies that the class of memory models admitting this approach is broad.
Lemma 3.3. Every prefix-closed memory model admits ( p w S C + 1 ) (\mathrm{pw}_{\mathrm{SC}} + 1) ( pw SC + 1 ) -pw-bounded witnesses.
Execution Graphs as Words
Section 3 reduces robustness to the search for a witness of pathwidth at most ℓ \ell ℓ , with ℓ = p w S C + 1 \ell= \mathrm{pw}_{\mathrm{SC}} + 1 ℓ = pw SC + 1 when MM is prefix-closed. In this section we turn that search into a search over words. We develop a graph algebra whose operations build execution graphs (§ 4.1 ), and show that its words with k + 1 k + 1 k + 1 colors denote exactly the graphs of pathwidth at most k k k (§ 4.2 ).
A Graph Algebra
We now introduce an algebra whose operations build execution graphs. It is similar in spirit to the HR-algebra of Courcelle [25 ] , which builds graphs with distinguished vertices. Our algebra is simpler, as it has no operation that glues two graphs together. So, its terms are words rather than trees, and they correspond to path decompositions rather than tree decompositions.
Free execution graphs. A free execution graph is a tuple G = ⟨ E , s b , r f , m b ⟩ G = \langle E, \mathrm{sb}, \mathrm{rf}, \mathrm{mb} \rangle G = ⟨ E , sb , rf , mb ⟩ , where E ⊆ E E \subseteq E E ⊆ E is a finite set of events and s b \mathrm{sb} sb , r f \mathrm{rf} rf , and m b \mathrm{mb} mb are arbitrary binary relations over E E E , i.e., with none of the constraints of § 2.2 . For example, in a free execution graph s b \mathrm{sb} sb may be cyclic. Path decompositions and pathwidth (§ 3.1 ) apply to free execution graphs unchanged. Identifiers only serve to distinguish events that carry the same label, so we consider two free execution graphs equal if they differ only by a renaming of identifiers.
CFE graphs. Given k ∈ N k \in\mathbb{N} k ∈ N , we take the set [ k ] [k] [ k ] as our colors. A colored free execution (CFE) graph is a tuple G c = ⟨ E , s b , r f , m b , χ ⟩ G_c = \langle E, \mathrm{sb}, \mathrm{rf}, \mathrm{mb}, \chi\rangle G c = ⟨ E , sb , rf , mb , χ ⟩ , where ⟨ E , s b , r f , m b ⟩ \langle E, \mathrm{sb}, \mathrm{rf}, \mathrm{mb} \rangle ⟨ E , sb , rf , mb ⟩ is a free execution graph and χ : E ⇀ [ k ] \chi: E \rightharpoonup[k] χ : E ⇀ [ k ] is a partial injective function. We call e ∈ dom ( χ ) e \in\operatorname{dom}(\chi) e ∈ dom ( χ ) a colored event , and e ∈ E ∖ dom ( χ ) e \in E \setminus\operatorname{dom}(\chi) e ∈ E ∖ dom ( χ ) an uncolored event . We call c ∈ img ( χ ) c \in\operatorname{img}(\chi) c ∈ img ( χ ) an active color , and c ∈ [ k ] ∖ img ( χ ) c \in[k] \setminus\operatorname{img}(\chi) c ∈ [ k ] ∖ img ( χ ) an inactive color . We write ⊥ \perp ⊥ for the empty CFE graph, in which E E E , all three relations, and χ \chi χ are empty.
Operations. We define three operations on a CFE graph G c = ⟨ E , s b , r f , m b , χ ⟩ G_c = \langle E, \mathrm{sb}, \mathrm{rf}, \mathrm{mb}, \chi\rangle G c = ⟨ E , sb , rf , mb , χ ⟩ , analogous to the steps of very nice path decompositions (§ 3.1 ). In each case, G c ′ = ⟨ E ′ , s b ′ , r f ′ , m b ′ , χ ′ ⟩ G'_c = \langle E', \mathrm{sb}', \mathrm{rf}', \mathrm{mb}', \chi' \rangle G c ′ = ⟨ E ′ , sb ′ , rf ′ , mb ′ , χ ′ ⟩ denotes the resulting graph, and any component not explicitly mentioned is unchanged.
Intro ( l a b , c ) \operatorname{Intro}(\mathrm{lab}, c) Intro ( lab , c ) , where l a b ∈ L a b \mathrm{lab} \in\mathrm{Lab} lab ∈ Lab and c ∈ [ k ] ∖ img ( χ ) c \in[k] \setminus\operatorname{img}(\chi) c ∈ [ k ] ∖ img ( χ ) : it introduces a new event carrying the label l a b \mathrm{lab} lab and the color c c c . Formally, letting e ≔ ⟨ ∣ E ∣ + 1 , l a b ⟩ e \coloneqq\langle|E| + 1, \mathrm{lab} \rangle e : = ⟨ ∣ E ∣ + 1 , lab ⟩ , we set E ′ ≔ E ∪ { e } E' \coloneqq E \cup\{e\} E ′ : = E ∪ { e } and χ ′ ≔ χ ∪ { e ↦ c } \chi' \coloneqq\chi\cup\{e \mapsto c\} χ ′ : = χ ∪ { e ↦ c } .
Forget ( c ) \operatorname{Forget}(c) Forget ( c ) , where c ∈ img ( χ ) c \in\operatorname{img}(\chi) c ∈ img ( χ ) : it uncolors the event with color c c c , which makes c c c inactive. Formally, letting e e e be the unique event with χ ( e ) = c \chi(e) = c χ ( e ) = c , χ ′ ≔ χ ∖ { e ↦ c } \chi' \coloneqq\chi\setminus\{e \mapsto c\} χ ′ : = χ ∖ { e ↦ c } .
Intro b ( c 1 , c 2 ) \operatorname{Intro}_b(c_1, c_2) Intro b ( c 1 , c 2 ) , where b ∈ { s b , r f , m b } b \in\{\mathrm{sb}, \mathrm{rf}, \mathrm{mb}\} b ∈ { sb , rf , mb } , c 1 , c 2 ∈ img ( χ ) c_1, c_2 \in\operatorname{img}(\chi) c 1 , c 2 ∈ img ( χ ) , and ⟨ χ − 1 ( c 1 ) , χ − 1 ( c 2 ) ⟩ ≠ b \langle\chi^{-1}(c_1), \chi^{-1}(c_2) \rangle\ne b ⟨ χ − 1 ( c 1 ) , χ − 1 ( c 2 )⟩ = b : it adds a b b b -edge between the events with colors c 1 c_1 c 1 and c 2 c_2 c 2 . Formally, letting e i ≔ χ − 1 ( c i ) e_i \coloneqq\chi^{-1}(c_i) e i : = χ − 1 ( c i ) , we set b ′ ≔ b ∪ { ⟨ e 1 , e 2 ⟩ } b' \coloneqq b \cup\{\langle e_1,e_2\rangle\} b ′ : = b ∪ {⟨ e 1 , e 2 ⟩} . We write Intro s b \operatorname{Intro}_{\mathrm{sb}} Intro sb , Intro r f \operatorname{Intro}_{\mathrm{rf}} Intro rf , and Intro m b \operatorname{Intro}_{\mathrm{mb}} Intro mb when the relation of Intro b \operatorname{Intro}_b Intro b is fixed.
Each operation has preconditions for it to be valid: c c c must be inactive for Intro ( l a b , c ) \operatorname{Intro}(\mathrm{lab}, c) Intro ( lab , c ) , and the colors in its arguments must be active for Forget ( c ) \operatorname{Forget}(c) Forget ( c ) and Intro b ( c 1 , c 2 ) \operatorname{Intro}_b(c_1,c_2) Intro b ( c 1 , c 2 ) , where the edge must moreover be new. When G c G_c G c satisfies the precondition of op \operatorname{op} op , we write op ( G c ) \operatorname{op}(G_c) op ( G c ) for the resulting graph.
Words Representing Path Decompositions
We use the operations above to define words that define bounded-pathwidth execution graphs.
The alphabet. Given k ∈ N k \in\mathbb{N} k ∈ N , let
Ops ( k ) ≔ { Intro ( l a b , c ) ∣ l a b ∈ L a b , c ∈ [ k ] } ∪ { Forget ( c ) ∣ c ∈ [ k ] } ∪ { Intro b ( c 1 , c 2 ) ∣ b ∈ { s b , r f , m b } , c 1 , c 2 ∈ [ k ] } \operatorname{Ops}(k) \coloneqq\{\operatorname{Intro}(\mathrm{lab},c) \mid\mathrm{lab} \in\mathrm{Lab},\ c \in[k]\} \cup\{\operatorname{Forget}(c) \mid c \in[k]\}
\cup\{\operatorname{Intro}_b(c_1,c_2) \mid b \in\{\mathrm{sb},\mathrm{rf},\mathrm{mb}\},\ c_1,c_2 \in[k]\} Ops ( k ) : = { Intro ( lab , c ) ∣ lab ∈ Lab , c ∈ [ k ]} ∪ { Forget ( c ) ∣ c ∈ [ k ]} ∪ { Intro b ( c 1 , c 2 ) ∣ b ∈ { sb , rf , mb } , c 1 , c 2 ∈ [ k ]}
be the set of operation symbols with k k k colors. The size of Ops ( k ) \operatorname{Ops}(k) Ops ( k ) is k ⋅ ∣ Lab ∣ + k + 3 ⋅ k 2 k \cdot|\operatorname{Lab}| + k + 3 \cdot k^{2} k ⋅ ∣ Lab ∣ + k + 3 ⋅ k 2 . We write ε \varepsilon ε for the empty word and, for w ∈ Ops ( k ) ∗ w \in\operatorname{Ops}(k)^{*} w ∈ Ops ( k ) ∗ , w i w_i w i for the prefix of w w w of length i i i , so w 0 = ε w_0 = \varepsilon w 0 = ε .
Well-formed and closed words. We define well-formedness of w ∈ Ops ( k ) ∗ w \in\operatorname{Ops}(k)^{*} w ∈ Ops ( k ) ∗ , and the CFE graph G c w G_c^w G c w induced by a well-formed w w w , by induction on w w w . The empty word is well-formed, with G c ε ≜ ⊥ G_c^{\varepsilon} \triangleq\perp G c ε ≜ ⊥ . The word w ⋅ op w \cdot\operatorname{op} w ⋅ op is well-formed if w w w is well-formed and G c w G_c^w G c w satisfies the precondition of op \operatorname{op} op ; then, G c w op ≜ op ( G c w ) G_c^{w\operatorname{op}} \triangleq\operatorname{op}(G_c^w) G c w op ≜ op ( G c w ) . We write χ w \chi^w χ w for the coloring of G c w G_c^w G c w , and G w G^w G w for the free execution graph obtained by discarding χ w \chi^w χ w . A CFE graph is closed if it has no colored event, and a word w w w is closed if it is well-formed and G c w G_c^w G c w is closed, i.e., dom ( χ w ) = ∅ \operatorname{dom}(\chi^w) = \varnothing dom ( χ w ) = ∅ .
Words and pathwidth. A closed word w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ of length n − 1 n-1 n − 1 defines a very nice path decomposition X 1 , … , X n X_1, \ldots, X_n X 1 , … , X n of G w G^w G w , where X i + 1 X_{i+1} X i + 1 contains the events that are colored at the end of the prefix w i w_i w i of w w w . This is illustrated in Figure 4 , and made formal in the following lemma.
Figure 4. A graph G G G (a), and a very nice path decomposition of G G G , along with the word w ∈ Ops ( 3 ) w \in\operatorname{Ops}(3) w ∈ Ops ( 3 ) it yields (b).
Lemma 4.1. For any closed w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ , the sequence X w 0 , X w 1 , … , X w ∣ w ∣ X_{w_0}, X_{w_1}, \ldots, X_{w_{|w|}} X w 0 , X w 1 , … , X w ∣ w ∣ , where X w i ≜ dom ( χ w i ) X_{w_i} \triangleq\operatorname{dom}(\chi^{w_i}) X w i ≜ dom ( χ w i ) , is a very nice path decomposition of G w G^w G w of width at most k k k , in which each bag X w i X_{w_i} X w i with i ≥ 1 i \ge1 i ≥ 1 is labeled by the step corresponding to the i i i -th operation of w w w . Conversely, for any free execution graph G G G and very nice path decomposition X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X 1 , X 2 , … , X n of G G G of width at most k k k , there is a closed w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ of length n − 1 n-1 n − 1 such that G w = G G^w = G G w = G and X w i = X i + 1 X_{w_i} = X_{i+1} X w i = X i + 1 for every i ∈ { 0 , … , n − 1 } i \in\{0, \ldots, n-1\} i ∈ { 0 , … , n − 1 } .
A direct corollary of Lemma 4.1 and Lemma 3.1 is that a free execution graph G G G has pathwidth at most k k k iff there is a closed word w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ such that G = G w G = G^w G = G w . This is the analogue of a result of [24 ] for the HR-algebra, where the graphs denoted by terms with k + 1 k+1 k + 1 sources are exactly the graphs of treewidth at most k k k . Here, the colors play the role of the sources.
Automata over Ops ( k + 1 ) \operatorname{Ops}(k+1) Ops ( k + 1 ) . In the following sections, we build automata that read words over Ops ( k + 1 ) \operatorname{Ops}(k+1) Ops ( k + 1 ) , and we use each such automaton to describe a set of free execution graphs. A free execution graph belongs to this set if it is G w G^w G w for some closed word w w w and the automaton accepts w w w . By Lemma 4.1, every such G w G^w G w has pathwidth at most k k k , and every free execution graph of pathwidth at most k k k equals G w G^w G w for some closed w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ . Taking k = ℓ k = \ell k = ℓ thus makes the words over Ops ( ℓ + 1 ) \operatorname{Ops}(\ell+1) Ops ( ℓ + 1 ) a search space for ℓ \ell ℓ -pw-bounded witnesses.
An Automaton for Recognizing Non-Robustness Witnesses
A witness for the non-MM-robustness of P is an execution graph G G G with ⟨ G , E , G . s b ⟩ ∈ G ( P ) \langle G,E,G.\mathit{sb}\rangle\in\mathcal{G}(P) ⟨ G , E , G . sb ⟩ ∈ G ( P ) , G ⊭ M M G \not\models\mathit{MM} G ⊨ MM and G ⊭ S C G \not\models\mathit{SC} G ⊨ SC . For each condition, we build an automaton that accepts all words w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ for which G w G^w G w satisfies it: Section 5.1 performs some preparatory checks on the well-formedness of w w w and G w G^w G w , Section 5.2 checks that G w G^w G w represents the execution of P, and Section 5.3 that G w G^w G w is consistent/inconsistent in a KAT memory model. Throughout, we bound the size of each automaton by an exponential in the input parameters, while each transition can be written down in polynomial time. For the most part, we give a high-level description of these automata, aiming at readability and intuitiveness. Their formal construction appears in Section E.
Recognizing Well-Formedness
Free execution graphs may not be execution graphs; for instance, r f \mathrm{rf} rf may relate events on different locations, or s b \mathrm{sb} sb may contain cycles. The following lemma takes care of such ill-formed graphs.
Lemma 5.1. For every k ∈ N k \in\mathbb{N} k ∈ N , there is a deterministic automaton A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k with 2 O ( k 2 + k log ∣ L a b ∣ + ∣ T i d ∣ + ∣ L o c ∣ ) 2^{O(k^{2}+k\log|\mathrm{Lab}|+|\mathrm{Tid}|+|\mathrm{Loc}|)} 2 O ( k 2 + k l o g ∣ Lab ∣ + ∣ Tid ∣ + ∣ Loc ∣ ) states that accepts w ∈ O p s ( k + 1 ) ∗ w \in\mathrm{Ops}(k+1)^{*} w ∈ Ops ( k + 1 ) ∗ iff w w w is closed and G w G^{w} G w is an execution graph.
The automaton A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k is the product of four deterministic automata: A f o r m k \mathcal{A}^{k}_{\mathrm{form}} A form k checks that w w w itself is closed, and A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k and A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k check that the respective relation is well-formed.
Closedness of the word. A word is closed if each of its operations meets its preconditions, and no color is active at the end. All conditions depend only on the active colors and on the edges between their events. For example, I n t r o s b ( c 1 , c 2 ) \mathrm{Intro}_{\mathrm{sb}}(c_{1},c_{2}) Intro sb ( c 1 , c 2 ) requires that c 1 c_{1} c 1 and c 2 c_{2} c 2 are active colors (i.e., they color events of the graph), and that no sb-edge has been drawn between c 1 c_{1} c 1 and c 2 c_{2} c 2 since these were last introduced. A state of A f o r m k \mathcal{A}^{k}_{\mathrm{form}} A form k is, thus, a pair ⟨ Q a c t , Q e d g ⟩ \langle Q_{\mathrm{act}}, Q_{\mathrm{edg}}\rangle ⟨ Q act , Q edg ⟩ , where Q a c t ⊆ [ k + 1 ] Q_{\mathrm{act}} \subseteq[k+1] Q act ⊆ [ k + 1 ] is the set of active colors and Q e d g ⊆ { s b , r f , m b } × Q a c t × Q a c t Q_{\mathrm{edg}} \subseteq\{\mathrm{sb},\mathrm{rf},\mathrm{mb}\}\times Q_{\mathrm{act}}\times Q_{\mathrm{act}} Q edg ⊆ { sb , rf , mb } × Q act × Q act records the edges drawn between their events. Following the previous example, I n t r o s b ( c 1 , c 2 ) \mathrm{Intro}_{\mathrm{sb}}(c_{1},c_{2}) Intro sb ( c 1 , c 2 ) can be executed if c 1 , c 2 ∈ Q a c t c_{1},c_{2} \in Q_{\mathrm{act}} c 1 , c 2 ∈ Q act and ⟨ s b , c 1 , c 2 ⟩ ∉ Q e d g \langle\mathrm{sb},c_{1},c_{2}\rangle\notin Q_{\mathrm{edg}} ⟨ sb , c 1 , c 2 ⟩ ∈ / Q edg .
Well-formedness of sb. The relation sb is well-formed iff, for each thread, (i) all events have exactly one incoming sb-edge, except one, which has none, (ii) all events have exactly one outgoing sb-edge, except one, which has none, and (iii) all events are connected. Note that sb may not be built incrementally, in general, which introduces some bookkeeping for checking the above conditions. We call an event of a thread with no incoming or outgoing sb-edge a first or last event, respectively. For Conditions (i) and (ii), it suffices to record which colored events already have an incoming and an outgoing edge, and for which threads a first and a last event has already been forgotten. For Condition (iii), we record which colored events are connected.
A state of A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k is, thus, a tuple ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ \langle Q_{\mathrm{in}}, Q_{\mathrm{out}}, Q_{\mathrm{fst}}, Q_{\mathrm{lst}}, \lambda_{\mathrm{rep}}, \lambda_{\mathrm{thr}}\rangle ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ thr ⟩ . Here, Q i n , Q o u t ⊆ [ k + 1 ] Q_{\mathrm{in}}, Q_{\mathrm{out}} \subseteq[k+1] Q in , Q out ⊆ [ k + 1 ] are the active colors whose events have an incoming, respectively outgoing, sb-edge, and Q f s t , Q l s t ⊆ T i d Q_{\mathrm{fst}}, Q_{\mathrm{lst}} \subseteq\mathrm{Tid} Q fst , Q lst ⊆ Tid are the threads that have an uncolored first, respectively last, event. This information suffices to verify Conditions (i) and (ii). Moreover, λ r e p : [ k + 1 ] → [ k + 1 ] \lambda_{\mathrm{rep}} : [k+1] \to[k+1] λ rep : [ k + 1 ] → [ k + 1 ] represents the connected components induced by sb, where each color is mapped to the smallest color in the same component, and λ t h r : [ k + 1 ] → T i d \lambda_{\mathrm{thr}} : [k+1] \to\mathrm{Tid} λ thr : [ k + 1 ] → Tid maps each active color to the thread of its event. This information suffices to verify Condition (iii): λ t h r \lambda_{\mathrm{thr}} λ thr allows to gather all colors of a thread, and λ r e p \lambda_{\mathrm{rep}} λ rep to check that all such colors belong to the same component. Figure 5 illustrates A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k on an example.
Figure 5. Three consecutive states ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ \langle Q_{\mathrm{in}}, Q_{\mathrm{out}}, Q_{\mathrm{fst}}, Q_{\mathrm{lst}}, \lambda_{\mathrm{rep}}, \lambda_{\mathrm{thr}}\rangle ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ thr ⟩ of A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , and the operations read between them. Above each state, we draw G w G^{w} G w restricted to sb, where w w w is the word read so far; all its events belong to thread t 1 t_{1} t 1 . The events in the dashed region are those that currently have a color (i.e., the bag of the corresponding path decomposition), which is written next to each of them; the others have been forgotten.
Well-formedness of rf and mb. A state of A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k is a pair ⟨ λ l a b , Q s r c ⟩ \langle\lambda_{\mathrm{lab}},Q_{\mathrm{src}}\rangle ⟨ λ lab , Q src ⟩ , where λ l a b : [ k + 1 ] ⇀ L a b \lambda_{\mathrm{lab}}:[k+1]\rightharpoonup\mathrm{Lab} λ lab : [ k + 1 ] ⇀ Lab maps each active color to the label of its event, and Q s r c ⊆ [ k + 1 ] Q_{\mathrm{src}}\subseteq[k+1] Q src ⊆ [ k + 1 ] is the set of active colors representing reading events without yet an rf-edge. A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k checks that every new edge Intro r f ( c 1 , c 2 ) \operatorname{Intro}_{\mathrm{rf}}(c_{1},c_{2}) Intro rf ( c 1 , c 2 ) is valid (e.g., c 1 , c 2 c_{1},c_{2} c 1 , c 2 represent events on the same location, and the event of c 2 c_{2} c 2 does not have an incoming rf-edge). Moreover, Forget ( c ) \operatorname{Forget}(c) Forget ( c ) requires c ∉ Q s r c c\notin Q_{\mathrm{src}} c ∈ / Q src , so that every reading event receives its incoming rf-edge before its color is forgotten. The well-formedness requirements of mb are identical to those of sb, with locations replacing threads and r events excluded. A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k is, likewise, similar to A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k .
Recognizing Executions of P
The following lemma ensures that the guessed graph G w G^{w} G w is valid for the program P.
Lemma 5.2. For every k ∈ N k\in\mathbb{N} k ∈ N and concurrent program P, there exists a word automaton A P k \mathcal{A}^{k}_{\mathrm{P}} A P k with O ( ∣ P ∣ k + 1 ) 2 O ( k ) O(|P|^{k+1})\,2^{O(k)} O ( ∣ P ∣ k + 1 ) 2 O ( k ) states such that, for every w ∈ L ( A w f k ) w\in L(\mathcal{A}^{k}_{\mathrm{wf}}) w ∈ L ( A wf k ) , A P k \mathcal{A}^{k}_{\mathrm{P}} A P k accepts w w w iff ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^{w}.E,G^{w}.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Fix a concurrent program P = ⟨ P s e q t 1 , … , P s e q t ∣ T i d ∣ ⟩ P=\langle\mathrm{Pseq}_{t_{1}},\ldots,\mathrm{Pseq}_{t_{|\mathrm{Tid}|}}\rangle P = ⟨ Pseq t 1 , … , Pseq t ∣ Tid ∣ ⟩ . When an event of a thread t t t is introduced, A P k \mathcal{A}^{k}_{\mathrm{P}} A P k guesses a transition of P s e q t \mathrm{Pseq}_{t} Pseq t that emits the label of that event. This guess is nondeterministic, as several transitions may emit the same label. A state of A P k \mathcal{A}^{k}_{\mathrm{P}} A P k is, thus, a pair ⟨ Q s r c , λ t r ⟩ \langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle ⟨ Q src , λ tr ⟩ , where λ t r : [ k + 1 ] ⇀ ⋃ t ∈ T i d Δ t \lambda_{\mathrm{tr}}:[k+1]\rightharpoonup\bigcup_{t\in\mathrm{Tid}}\Delta_{t} λ tr : [ k + 1 ] ⇀ ⋃ t ∈ Tid Δ t maps each active color to the transition guessed for its event, and Q s r c ⊆ [ k + 1 ] Q_{\mathrm{src}}\subseteq[k+1] Q src ⊆ [ k + 1 ] is the set of active colors whose events have no incoming sb-edge yet. When a sb-edge is drawn from c 1 c_{1} c 1 to c 2 c_{2} c 2 , tgt ( λ t r ( c 1 ) ) \operatorname{tgt}(\lambda_{\mathrm{tr}}(c_{1})) tgt ( λ tr ( c 1 )) must reach src ( λ t r ( c 2 ) ) \operatorname{src}(\lambda_{\mathrm{tr}}(c_{2})) src ( λ tr ( c 2 )) by silent transitions. Similarly, when a color c ∈ Q s r c c\in Q_{\mathrm{src}} c ∈ Q src is forgotten, its event is the first of its thread t t t , so src ( λ t r ( c ) ) \operatorname{src}(\lambda_{\mathrm{tr}}(c)) src ( λ tr ( c )) must be reachable from the initial state of P s e q t \mathrm{Pseq}_{t} Pseq t by silent transitions. Figure 6 shows two steps of A P k \mathcal{A}^{k}_{\mathrm{P}} A P k .
Figure 6. Three consecutive states ⟨ Q s r c , λ t r ⟩ \langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle ⟨ Q src , λ tr ⟩ of A P k \mathcal{A}^{k}_{\mathrm{P}} A P k , for the program P of Figure 1 a, and the operations read between them. Above each state, we draw G s b w G^{w}_{\mathrm{sb}} G sb w , where w w w is the word read so far; its events are e 1 , … , e 4 e_{1},\ldots,e_{4} e 1 , … , e 4 of Figure 1 b. The events in the dashed region are those that currently have a color, which is written next to each of them; the others have been forgotten. We write δ i , j \delta_{i,j} δ i , j for the j j j -th transition of P s e q t i \mathrm{Pseq}_{t_{i}} Pseq t i .
Recognizing MM-consistency
Finally, here we construct automata for checking memory model (in)consistency. The construction is more involved than the automata we have seen so far, and one of the main technical contributions of this work. We thus present it in more detail.
Lemma 5.3. For every k ∈ N k\in\mathbb{N} k ∈ N and memory model MM, there is a deterministic word automaton A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k with 2 O ( k 2 ⋅ ∣ M M ∣ 2 ) 2^{O(k^{2}\cdot|\mathrm{MM}|^{2})} 2 O ( k 2 ⋅ ∣ MM ∣ 2 ) states such that, for every w ∈ L ( A w f k ) w\in L(\mathcal{A}^{k}_{\mathrm{wf}}) w ∈ L ( A wf k ) , A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k accepts w w w iff G w ⊨ M M G^{w}\models\mathrm{MM} G w ⊨ MM . Complementing A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k yields a deterministic word automaton A ‾ M M k \overline{\mathcal{A}}^{k}_{\mathrm{MM}} A MM k with the same states that, for every w ∈ L ( A w f k ) w\in L(\mathcal{A}^{k}_{\mathrm{wf}}) w ∈ L ( A wf k ) , accepts w w w iff G w ⊭ M M G^{w}\not\models\mathrm{MM} G w ⊨ MM .
Fix a memory model MM, and let K M M = ⟨ Q , T e s t s ∪ R e l , Δ , i n i t , Q F ⟩ \mathcal{K}_{\mathrm{MM}}=\langle Q,\mathrm{Tests}\cup\mathrm{Rel},\Delta,\mathrm{init},Q_{\mathrm{F}}\rangle K MM = ⟨ Q , Tests ∪ Rel , Δ , init , Q F ⟩ be a KAT-NFA for MM. Recall that G ⊨ M M G\models\mathrm{MM} G ⊨ MM iff no word accepted by K M M \mathcal{K}_{\mathrm{MM}} K MM has a cyclic realization in G G G . So, A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k has to detect such cyclic realizations in G w G^{w} G w while reading w w w . The difficulty is that a realization may be arbitrarily long and visit (or even start at) events that are forgotten by the end of w w w , where the violation happens. The key insight underpinning Lemma 5.3 is that it is possible and sufficient to summarize each realization in its (colored) endpoints, by keeping track of the states of K M M \mathcal{K}_{\mathrm{MM}} K MM that it connects.
Throughout, w w w is well-formed and G c w = ⟨ E , s b , r f , m b , χ ⟩ G^w_c = \langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb},\chi\rangle G c w = ⟨ E , sb , rf , mb , χ ⟩ , and we write e c ≜ χ − 1 ( c ) e_c \triangleq\chi^{-1}(c) e c ≜ χ − 1 ( c ) for the event of an active color c c c . A walk from e e e to e ′ e' e ′ is a pair of a word u ∈ ( T e s t s ∪ R e l ) ∗ u \in(\mathrm{Tests} \cup\mathrm{Rel})^* u ∈ ( Tests ∪ Rel ) ∗ and a realization e 0 , e 1 , … , e m e_0,e_1,\ldots,e_m e 0 , e 1 , … , e m of u u u in G w G^w G w from e 0 = e e_0=e e 0 = e to e m = e ′ e_m=e' e m = e ′ . Unlike a realization, a walk thus fixes the word it realizes. Its interior consists of the events e 1 , … , e m − 1 e_1,\ldots,e_{m-1} e 1 , … , e m − 1 . We say that the walk leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q q q to q ′ q' q ′ if K M M \mathcal{K}_{\mathrm{MM}} K MM has a run on u u u from q q q to q ′ q' q ′ . In these terms, G w ⊭ M M G^w \not\models\mathrm{MM} G w ⊨ MM iff some walk from an event to itself leads K M M \mathcal{K}_{\mathrm{MM}} K MM from init to a state of Q F Q_F Q F . We call such a walk a violation.
Our construction rests on the observation that uncolored events never gain new edges, so a walk can only enter or leave uncolored events by passing through some colored event. The automaton summarizes a walk between two colored events with uncolored interior by storing colors of its endpoints and the states of K M M \mathcal{K}_{\mathrm{MM}} K MM it connects. This is recorded in the following tuples.
A tuple ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ [ k + 1 ] × [ k + 1 ] × Q × Q \langle c_1,c_2,q_1,q_2\rangle\in[k+1]\times[k+1]\times Q\times Q ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ [ k + 1 ] × [ k + 1 ] × Q × Q , with c 1 , c 2 ∈ img ( χ ) c_1,c_2 \in\operatorname{img}(\chi) c 1 , c 2 ∈ img ( χ ) , is a path summary of w w w if some walk from e c 1 e_{c_1} e c 1 to e c 2 e_{c_2} e c 2 with uncolored interior leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q 1 q_1 q 1 to q 2 q_2 q 2 ; and a cycle summary of w w w if, for some uncolored event e e e , some walk from e e e to e c 1 e_{c_1} e c 1 leads K M M \mathcal{K}_{\mathrm{MM}} K MM from init to q 1 q_1 q 1 , and some walk from e c 2 e_{c_2} e c 2 to e e e leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q 2 q_2 q 2 to a state of Q F Q_F Q F , both with uncolored interior.
We write Q p t h w Q^w_{\mathrm{pth}} Q pth w and Q c y c w Q^w_{\mathrm{cyc}} Q cyc w for the sets of path and cycle summaries of w w w . Intuitively, we store cycle summaries because a violation may still be formed by adding a walk from e c 1 e_{c_1} e c 1 to e c 2 e_{c_2} e c 2 that leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q 1 q_1 q 1 to q 2 q_2 q 2 . This violation cannot be cut into path summaries, as its first event may not be colored. In particular, when c 1 = c 2 c_1=c_2 c 1 = c 2 and q 1 = q 2 q_1=q_2 q 1 = q 2 , the empty walk at e c 1 e_{c_1} e c 1 is such a walk, so a cycle summary ⟨ c , c , q , q ⟩ \langle c,c,q,q\rangle ⟨ c , c , q , q ⟩ witnesses a violation (see Figure 7 ).
Figure 7. (a) shows an illustration of a cycle summary of Q c y c Q_{\mathrm{cyc}} Q cyc . In G c w G^w_c G c w , there exists an uncolored event e e e and walks e ⇝ e 1 e \leadsto e_1 e ⇝ e 1 and e 2 ⇝ e e_2 \leadsto e e 2 ⇝ e with words u 1 u_1 u 1 and u 2 u_2 u 2 , respectively. In K M M \mathcal{K}_{\mathrm{MM}} K MM , u 1 u_1 u 1 takes init to q 1 q_1 q 1 , and u 2 u_2 u 2 takes q 2 q_2 q 2 to q F ∈ Q F q_F \in Q_F q F ∈ Q F . In (b), the two walks end and start, respectively, on the same endpoint (event e 1 e_1 e 1 ), therefore closing a cycle on e e e with the word u 1 u 2 u_1u_2 u 1 u 2 . In K M M \mathcal{K}_{\mathrm{MM}} K MM , u 1 u 2 u_1u_2 u 1 u 2 takes init to q F ∈ Q F q_F \in Q_F q F ∈ Q F via q q q , thereby witnessing a violation.
States. A state of A M M k \mathcal{A}^k_{\mathrm{MM}} A MM k is a pair ⟨ Q p t h , Q c y c ⟩ \langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle ⟨ Q pth , Q cyc ⟩ of sets Q p t h , Q c y c ⊆ [ k + 1 ] × [ k + 1 ] × Q × Q Q_{\mathrm{pth}},Q_{\mathrm{cyc}} \subseteq[k+1]\times[k+1]\times Q\times Q Q pth , Q cyc ⊆ [ k + 1 ] × [ k + 1 ] × Q × Q , which hold path summaries and cycle summaries, respectively. If A M M k \mathcal{A}^k_{\mathrm{MM}} A MM k has a run on a well-formed word w w w , then the state it reaches after reading w w w is ⟨ Q p t h w , Q c y c w ⟩ \langle Q^w_{\mathrm{pth}},Q^w_{\mathrm{cyc}}\rangle ⟨ Q pth w , Q cyc w ⟩ . Each of Q p t h Q_{\mathrm{pth}} Q pth and Q c y c Q_{\mathrm{cyc}} Q cyc takes 2 ( k + 1 ) 2 ⋅ ∣ Q ∣ 2 2^{(k+1)^2\cdot|Q|^2} 2 ( k + 1 ) 2 ⋅ ∣ Q ∣ 2 values, where ∣ Q ∣ ≤ 2 ∣ M M ∣ + 2 |Q|\leq2|\mathrm{MM}|+2 ∣ Q ∣ ≤ 2∣ MM ∣ + 2 by Lemma 2.1.
The automaton detects violations when it forgets an event. Consider a violation, and the operation Forget ( c ) \operatorname{Forget}(c) Forget ( c ) that forgets the last of the events in the violation. Just before this operation, every event of the violation other than e c e_c e c is uncolored, so its first event is either e c e_c e c or an uncolored event. When the automaton forgets e c e_c e c , it lets walks pass through e c e_c e c . Cutting the violation at a visit to e c e_c e c , then, yields the two walks of a cycle summary ⟨ c , c , q , q ⟩ \langle c,c,q,q\rangle ⟨ c , c , q , q ⟩ , for some q ∈ Q q\in Q q ∈ Q . The automaton rejects as soon as such a tuple appears, before it discards the summaries that mention c c c . The initial state and unique accepting state are both ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ . Figure 8 shows a run of A M M k \mathcal{A}^k_{\mathrm{MM}} A MM k that detects a violation.
Figure 8. (a) shows a KAT-NFA K M M \mathcal{K}_{\mathrm{MM}} K MM for M M = ( s b ∪ r f ) + \mathrm{MM}=(\mathrm{sb}\cup\mathrm{rf})^{+} MM = ( sb ∪ rf ) + , and (b) shows three consecutive states ⟨ Q p t h , Q c y c ⟩ \langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle ⟨ Q pth , Q cyc ⟩ of A M M 2 \mathcal{A}^{2}_{\mathrm{MM}} A MM 2 , and the operations read between them. Above each state, we draw G w G_{w} G w , where w w w is the word read so far. The events in the dashed region are those currently with a color, which is written next to each of them; the others have been forgotten. We omit from Q p t h Q_{\mathrm{pth}} Q pth the tuples ⟨ c , c , q , q ⟩ \langle c,c,q,q\rangle ⟨ c , c , q , q ⟩ of the empty walks. The last panel shows the sets computed by t c \mathrm{tc} tc when reading F o r g e t ( 1 ) \mathrm{Forget}(1) Forget ( 1 ) , which contain the violation ⟨ 2 , 2 , q 1 , q 1 ⟩ \langle2,2,q_{1},q_{1}\rangle ⟨ 2 , 2 , q 1 , q 1 ⟩ , so the run rejects.
Auxiliary functions. The transitions of A M M k \mathcal{A}^k_{\mathrm{MM}} A MM k are based on some auxiliary computations that we describe here. When a new event or edge is introduced, the only new walks with uncolored interior have empty interior: the empty walk and single tests at the new event, or a single step along the new edge. For c 1 , c 2 ∈ [ k + 1 ] c_{1},c_{2}\in[k+1] c 1 , c 2 ∈ [ k + 1 ] and a relation symbol or test l l l , the path summaries of a step labeled l l l from e c 1 e_{c_{1}} e c 1 to e c 2 e_{c_{2}} e c 2 are step ( c 1 , l , c 2 ) ≔ { ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∣ ⟨ q 1 , l , q 2 ⟩ ∈ Δ } \operatorname{step}(c_{1},l,c_{2})\coloneqq\{\langle c_{1},c_{2},q_{1},q_{2}\rangle\mid\langle q_{1},l,q_{2}\rangle\in\Delta\} step ( c 1 , l , c 2 ) : = {⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∣ ⟨ q 1 , l , q 2 ⟩ ∈ Δ } . We then let
addTests ( c , Q p t h , lab ) ≔ Q p t h ∪ { ⟨ c , c , q , q ⟩ ∣ q ∈ Q } ∪ ⋃ { step ( c , τ , c ) ∣ τ ∈ Tests , lab ∈ τ } , \operatorname{addTests}(c,Q_{\mathrm{pth}},\operatorname{lab})\coloneqq Q_{\mathrm{pth}}\cup\{\langle c,c,q,q\rangle\mid q\in Q\}\cup\bigcup\{\operatorname{step}(c,\tau,c)\mid\tau\in\operatorname{Tests},\operatorname{lab}\in\tau\}, addTests ( c , Q pth , lab ) : = Q pth ∪ {⟨ c , c , q , q ⟩ ∣ q ∈ Q } ∪ ⋃ { step ( c , τ , c ) ∣ τ ∈ Tests , lab ∈ τ } ,
addEdges ( c 1 , c 2 , Q p t h , b ) ≔ Q p t h ∪ step ( c 1 , b , c 2 ) ∪ step ( c 2 , b − 1 , c 1 ) . \operatorname{addEdges}(c_{1},c_{2},Q_{\mathrm{pth}},b)\coloneqq Q_{\mathrm{pth}}\cup\operatorname{step}(c_{1},b,c_{2})\cup\operatorname{step}(c_{2},b^{-1},c_{1}). addEdges ( c 1 , c 2 , Q pth , b ) : = Q pth ∪ step ( c 1 , b , c 2 ) ∪ step ( c 2 , b − 1 , c 1 ) .
addTests \operatorname{addTests} addTests adds the empty walk at e c e_{c} e c and the tests that its label lab \operatorname{lab} lab satisfies. addEdges \operatorname{addEdges} addEdges adds the new edge in both directions, as K M M \mathcal{K}_{\mathrm{MM}} K MM may traverse it backwards.
Forgetting a color c c c has two effects: walks may now pass through e c e_{c} e c , and e c e_{c} e c may be the first event of a violation. We define an operation tc ( c , Q p t h , Q c y c ) \operatorname{tc}(c,Q_{\mathrm{pth}},Q_{\mathrm{cyc}}) tc ( c , Q pth , Q cyc ) that returns ⟨ Q p t h ′ ′ , Q c y c ′ ′ ⟩ \langle Q_{\mathrm{pth}}^{\prime\prime},Q_{\mathrm{cyc}}^{\prime\prime}\rangle ⟨ Q pth ′′ , Q cyc ′′ ⟩ , where Q p t h ′ ′ Q_{\mathrm{pth}}^{\prime\prime} Q pth ′′ is the smallest set that contains Q p t h Q_{\mathrm{pth}} Q pth and satisfies the following rule.
(i) If ⟨ c 1 , c , q 1 , q ⟩ ∈ Q p t h ′ ′ \langle c_{1},c,q_{1},q\rangle\in Q_{\mathrm{pth}}^{\prime\prime} ⟨ c 1 , c , q 1 , q ⟩ ∈ Q pth ′′ and ⟨ c , c 2 , q , q 2 ⟩ ∈ Q p t h ′ ′ \langle c,c_{2},q,q_{2}\rangle\in Q_{\mathrm{pth}}^{\prime\prime} ⟨ c , c 2 , q , q 2 ⟩ ∈ Q pth ′′ , then ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q p t h ′ ′ \langle c_{1},c_{2},q_{1},q_{2}\rangle\in Q_{\mathrm{pth}}^{\prime\prime} ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q pth ′′ . This composes two path summaries at e c e_{c} e c .
Similarly, Q c y c ′ ′ Q_{\mathrm{cyc}}^{\prime\prime} Q cyc ′′ is the smallest set that contains Q c y c Q_{\mathrm{cyc}} Q cyc and satisfies the following rules.
(ii) If ⟨ c , c 2 , q , q 2 ⟩ ∈ Q c y c ′ ′ \langle c,c_{2},q,q_{2}\rangle\in Q_{\mathrm{cyc}}^{\prime\prime} ⟨ c , c 2 , q , q 2 ⟩ ∈ Q cyc ′′ and ⟨ c , c 1 , q , q 1 ⟩ ∈ Q p t h ′ ′ \langle c,c_{1},q,q_{1}\rangle\in Q_{\mathrm{pth}}^{\prime\prime} ⟨ c , c 1 , q , q 1 ⟩ ∈ Q pth ′′ , then ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q c y c ′ ′ \langle c_{1},c_{2},q_{1},q_{2}\rangle\in Q_{\mathrm{cyc}}^{\prime\prime} ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q cyc ′′ . This extends the walk into e c e_{c} e c of a cycle summary by a walk from e c e_{c} e c to e c 1 e_{c_{1}} e c 1 .
(iii) If ⟨ c 1 , c , q 1 , q ⟩ ∈ Q c y c ′ ′ \langle c_{1},c,q_{1},q\rangle\in Q_{\mathrm{cyc}}^{\prime\prime} ⟨ c 1 , c , q 1 , q ⟩ ∈ Q cyc ′′ and ⟨ c 2 , c , q 2 , q ⟩ ∈ Q p t h ′ ′ \langle c_{2},c,q_{2},q\rangle\in Q_{\mathrm{pth}}^{\prime\prime} ⟨ c 2 , c , q 2 , q ⟩ ∈ Q pth ′′ , then ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q c y c ′ ′ \langle c_{1},c_{2},q_{1},q_{2}\rangle\in Q_{\mathrm{cyc}}^{\prime\prime} ⟨ c 1 , c 2 , q 1 , q 2 ⟩ ∈ Q cyc ′′ . This extends the walk out of e c e_{c} e c of a cycle summary backwards, by
We write violationFree ( Q c y c ′ ′ ) \operatorname{violationFree}(Q_{\mathrm{cyc}}^{\prime\prime}) violationFree ( Q cyc ′′ ) when Q c y c ′ ′ Q_{\mathrm{cyc}}^{\prime\prime} Q cyc ′′ contains no tuple of the form ⟨ c ′ , c ′ , q , q ⟩ \langle c^{\prime},c^{\prime},q,q\rangle ⟨ c ′ , c ′ , q , q ⟩ . Finally, the operation erase ( c , Q p t h ′ ′ , Q c y c ′ ′ ) \operatorname{erase}(c,Q_{\mathrm{pth}}^{\prime\prime},Q_{\mathrm{cyc}}^{\prime\prime}) erase ( c , Q pth ′′ , Q cyc ′′ ) removes every tuple that mentions c c c from Q p t h ′ ′ Q_{\mathrm{pth}}^{\prime\prime} Q pth ′′ and Q c y c ′ ′ Q_{\mathrm{cyc}}^{\prime\prime} Q cyc ′′ .
Transition rules. Intro ( lab , c ) \operatorname{Intro}( \operatorname{lab},c) Intro ( lab , c ) adds the path summaries of the new walks at e c e_{c} e c , namely its empty walk and the tests that lab \operatorname{lab} lab satisfies. Intro b ( c 1 , c 2 ) \operatorname{Intro}_{b}(c_{1},c_{2}) Intro b ( c 1 , c 2 ) adds the path summaries of a single step along the new edge, in both directions. Both leave the cycle summaries unchanged, as these only change when uncoloring an event. Forget ( c ) \operatorname{Forget}(c) Forget ( c ) first lets walks pass through e c e_{c} e c , by computing tc \operatorname{tc} tc . It rejects if this reveals a violation; if not, it discards the summaries that mention c c c , as c c c is no longer active.
op = Intro ( l a b , c ) Q p t h ′ = addTests ( c , Q p t h , l a b ) ⟨ Q p t h , Q c y c ⟩ → op ⟨ Q p t h ′ , Q c y c ⟩ op = Intro b ( c 1 , c 2 ) , b ∈ { s b , r f , m b } Q p t h ′ = addEdges ( c 1 , c 2 , Q p t h , b ) ⟨ Q p t h , Q c y c ⟩ → op ⟨ Q p t h ′ , Q c y c ⟩ op = Forget ( c ) ⟨ Q p t h ′ ′ , Q c y c ′ ′ ⟩ = tc ( c , Q p t h , Q c y c ) , violationFree ( Q c y c ′ ′ ) , ⟨ Q p t h ′ , Q c y c ′ ⟩ = erase ( c , Q p t h ′ ′ , Q c y c ′ ′ ) ⟨ Q p t h , Q c y c ⟩ → op ⟨ Q p t h ′ , Q c y c ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intro}(\mathrm{lab},c) &
Q'_{\mathrm{pth}} &= \operatorname{addTests}(c,Q_{\mathrm{pth}},\mathrm{lab}) &
\langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle\\
\operatorname{op} &= \operatorname{Intro}_{b}(c_{1},c_{2}),\quad b\in\{\mathrm{sb},\mathrm{rf},\mathrm{mb}\} &
Q'_{\mathrm{pth}} &= \operatorname{addEdges}(c_{1},c_{2},Q_{\mathrm{pth}},b) &
\langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle\\
\operatorname{op} &= \operatorname{Forget}(c) &
\langle Q''_{\mathrm{pth}},Q''_{\mathrm{cyc}}\rangle&= \operatorname{tc}(c,Q_{\mathrm{pth}},Q_{\mathrm{cyc})},\quad\operatorname{violationFree}(Q''_{\mathrm{cyc}}),\quad\langle Q'_{\mathrm{pth}},Q'_{\mathrm{cyc}}\rangle=\operatorname{erase}(c,Q''_{\mathrm{pth}},Q''_{\mathrm{cyc}}) &
\langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{pth}},Q'_{\mathrm{cyc}}\rangle
\end{aligned} op op op = Intro ( lab , c ) = Intro b ( c 1 , c 2 ) , b ∈ { sb , rf , mb } = Forget ( c ) Q pth ′ Q pth ′ ⟨ Q pth ′′ , Q cyc ′′ ⟩ = addTests ( c , Q pth , lab ) = addEdges ( c 1 , c 2 , Q pth , b ) = tc ( c , Q pth , Q cyc ) , violationFree ( Q cyc ′′ ) , ⟨ Q pth ′ , Q cyc ′ ⟩ = erase ( c , Q pth ′′ , Q cyc ′′ ) ⟨ Q pth , Q cyc ⟩ ⟨ Q pth , Q cyc ⟩ ⟨ Q pth , Q cyc ⟩ op ⟨ Q pth ′ , Q cyc ⟩ op ⟨ Q pth ′ , Q cyc ⟩ op ⟨ Q pth ′ , Q cyc ′ ⟩
The Complexity of Robustness
Let P P P be a concurrent program, given by the instruction sequences S t S_t S t for t ∈ T i d t \in\mathrm{Tid} t ∈ Tid . Let N N N be the total size of the input, which consists of these sequences, together with explicit representations of T i d \mathrm{Tid} Tid , L o c \mathrm{Loc} Loc , R e g \mathrm{Reg} Reg , V a l \mathrm{Val} Val , A n n \mathrm{Ann} Ann , and of M M MM M M as a KAT expression.
Exploring the product. Consider any KAT-definable memory model M M MM M M that admits ℓ \ell ℓ -pw-bounded witnesses. Lemma 4.1, together with Lemmas 5.1 to 5.3, implies that
P P P is robust against M M ⟺ L ( A w f ℓ ) ∩ L ( A p ℓ ) ∩ L ( A M M ℓ ) ∩ L ( A ¬ S C ℓ ) = ∅ MM \Longleftrightarrow\mathcal{L}(A^\ell_{\mathrm{wf}}) \cap\mathcal{L}(A^\ell_{\mathrm{p}}) \cap\mathcal{L}(A^\ell_{MM}) \cap\mathcal{L}(A^\ell_{\neg\mathrm{SC}})=\varnothing M M ⟺ L ( A wf ℓ ) ∩ L ( A p ℓ ) ∩ L ( A M M ℓ ) ∩ L ( A ¬ SC ℓ ) = ∅ ,
with a word w w w of the intersection on the right-hand side representing a violation witness G w G^w G w .
Computing an explicit representation of the above automata (let alone their product) is prohibitive, as their size depends exponentially on N N N . However, (i) if their intersection is not empty, then it contains a word w w w of at most exponential length, and (ii) each automaton transition can be verified in polynomial space. These two facts lead to an NPSPACE decision procedure, by guessing and simulating on the fly the synchronous product of the above automata. Since NPSPACE = PSPACE, due to Savitch’s well-known theorem [11 ] , we thus obtain the following.
Theorem 5.4. Let M M MM M M be a KAT-definable memory model that admits ℓ \ell ℓ -pw-bounded witnesses, for some ℓ \ell ℓ bounded by a polynomial in N N N . Given instruction sequences S t S_t S t for t ∈ T i d t \in\mathrm{Tid} t ∈ Tid and explicit domains T i d \mathrm{Tid} Tid , L o c \mathrm{Loc} Loc , R e g \mathrm{Reg} Reg , V a l \mathrm{Val} Val , A n n \mathrm{Ann} Ann , deciding whether the induced program P P P is robust against M M MM M M is in PSPACE.
Prefix-closed models. Recall from Lemma 3.3 that every prefix-closed memory model admits ( p w S C + 1 ) (\mathrm{pw}_{\mathrm{SC}}+1) ( pw SC + 1 ) -pw-bounded witnesses. Since p w S C + 1 ≤ N + 1 \mathrm{pw}_{\mathrm{SC}}+1 \leq N+1 pw SC + 1 ≤ N + 1 , Theorem 5.4 applies to every prefix-closed memory model. Moreover, the KAT-NFA K M M K_{MM} K M M of Lemma 2.1 can be computed in polynomial time. This is because expanding the derived relations of M M MM M M yields an expression of size polynomial in ∣ M M ∣ |MM| ∣ M M ∣ and ∣ T i d ∣ + ∣ L o c ∣ + ∣ A n n ∣ |\mathrm{Tid}|+|\mathrm{Loc}|+|\mathrm{Ann}| ∣ Tid ∣ + ∣ Loc ∣ + ∣ Ann ∣ , and hence in N N N . We thus obtain Theorem 1.1.
A Sequential Monitor
The procedure of Theorem 5.4 guesses, for every event, a transition of the program that emits it, which is not efficient in practice. This is required for the generality of Theorem 5.4, which does not assume prefix-closedness of the memory model, but can be simplified under this assumption. Indeed, prefix-closedness allows us to consider the events of each thread in sb order. This allows us to replace A p k A^k_{\mathrm{p}} A p k of Lemma 5.2 by an automaton that is essentially a realization of the standard operational semantics of P P P , in the language of our graph algebra (§ 4 ) as opposed to the language of event labels. This treatment requires adapting our definitions on pathwidth.
Canonical pathwidth. A word w ∈ Ops ( k ) ∗ w \in\operatorname{Ops}(k)^* w ∈ Ops ( k ) ∗ is canonical if, for every edge e 1 → s b e 2 e_1 \xrightarrow{\mathrm{sb}} e_2 e 1 sb e 2 of G w G^w G w , the INTRO operation that introduced e 1 e_1 e 1 precedes that of e 2 e_2 e 2 in w w w . Similarly, a path decomposition of an execution graph is canonical if, for every edge e 1 → s b e 2 e_1 \xrightarrow{\mathrm{sb}} e_2 e 1 sb e 2 , the first bag containing e 1 e_1 e 1 comes before the first bag containing e 2 e_2 e 2 . The canonical pathwidth cpw ( G ) \operatorname{cpw}(G) cpw ( G ) of G G G is the smallest width of a canonical path decomposition of G G G . Thus, canonicity restricts the set of path decompositions of G G G , and the set of words w w w that yield G w G^w G w , implying pw ( G ) ≤ cpw ( G ) \operatorname{pw}(G) \leq\operatorname{cpw}(G) pw ( G ) ≤ cpw ( G ) . Lemma 4.1 has a direct analogue: canonical words over Ops ( k + 1 ) \operatorname{Ops}(k+1) Ops ( k + 1 ) describe exactly the graphs of canonical pathwidth at most k k k . The bound of Lemma 3.2 still holds for cpw \operatorname{cpw} cpw , because the path decomposition in its proof is canonical.
Lemma 6.1. For every execution graph G G G , if G ⊨ S C G \models\mathrm{SC} G ⊨ SC then pw ( G ) ≤ cpw ( G ) ≤ p w S C \operatorname{pw}(G) \le\operatorname{cpw}(G) \le\mathrm{pw}_{\mathrm{SC}} pw ( G ) ≤ cpw ( G ) ≤ pw SC .
Canonical-pathwidth-bounded witnesses. We define ℓ \ell ℓ -cpw-bounded witnesses as in § 3.2 , with cpw \operatorname{cpw} cpw in place of pw \operatorname{pw} pw . Prefix-closed memory models admit ℓ \ell ℓ -cpw-bounded witnesses, but for a slightly larger ℓ \ell ℓ compared to pw -bounded, as the following lemma states. Intuitively, this is because canonicity forces the last event e e e of a witness G G G that causes the violation to be introduced in a bag towards the end of the path decomposition of G G G , and thus its neighboring events (in terms of r f \mathrm{rf} rf and m b \mathrm{mb} mb edges) must also be carried through until that bag.
Lemma 6.2. Every prefix-closed memory model admits ( p w S C + 3 ) (\mathrm{pw}_{\mathrm{SC}}+3) ( pw SC + 3 ) -cpw-bounded witnesses, and ( p w S C + 2 ) (\mathrm{pw}_{\mathrm{SC}}+2) ( pw SC + 2 ) -cpw-bounded witnesses if every RMW reads from its m b \mathrm{mb} mb -predecessor.
The A S k A_{\mathrm{S}}^{k} A S k automaton
We now replace A P k A_{\mathrm{P}}^{k} A P k by an automaton A S k A_{\mathrm{S}}^{k} A S k , with the following guarantees.
Lemma 6.3. Consider a concurrent program P \mathrm{P} P given as a collection of instruction sequences ⟨ S t ⟩ t ∈ T i d \langle S_t\rangle_{t\in\mathrm{Tid}} ⟨ S t ⟩ t ∈ Tid , and their respective LTSs ⟨ P s e q t ⟩ t ∈ T i d \langle P\mathrm{seq}_t\rangle_{t\in\mathrm{Tid}} ⟨ P seq t ⟩ t ∈ Tid . For every k ∈ N k\in\mathbb{N} k ∈ N , there exists a word automaton A S k A_{\mathrm{S}}^{k} A S k with O ( n ∣ T i d ∣ ⋅ ( ∣ V a l ∣ + 1 ) ∣ R e g ∣ ⋅ 2 O ( ( k + ∣ T i d ∣ ) log k ) ) O\left(n^{|\mathrm{Tid}|}\cdot(|\mathrm{Val}|+1)^{|\mathrm{Reg}|}\cdot2^{O((k+|\mathrm{Tid}|)\log k)}\right) O ( n ∣ Tid ∣ ⋅ ( ∣ Val ∣ + 1 ) ∣ Reg ∣ ⋅ 2 O (( k + ∣ Tid ∣ ) l o g k ) ) states, where n = max t ∈ T i d n t n=\max_{t\in\mathrm{Tid}}n_t n = max t ∈ Tid n t , such that, for every w ∈ L ( A W F k ) w\in\mathcal{L}(A_{\mathrm{WF}}^{k}) w ∈ L ( A WF k ) , A S k A_{\mathrm{S}}^{k} A S k accepts w w w iff w w w is canonical and ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G_{w}.E,G_{w}.\mathrm{sb}\rangle\in\mathcal{G}(\mathrm{P}) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Intuitively, A S k A_{\mathrm{S}}^{k} A S k realizes the standard operational semantics of P \mathrm{P} P , but instead of emitting event labels (e.g., r a ( t , x , v ) r_a(t,x,v) r a ( t , x , v ) ), it emits the respective operation in Ops ( k + 1 ) \operatorname{Ops}(k+1) Ops ( k + 1 ) (e.g., Intro ( r a ( t , x , v ) , c ) \operatorname{Intro}(r_a(t,x,v),c) Intro ( r a ( t , x , v ) , c ) , for some color c c c ). It also performs some bookkeeping in order to introduce sb edges (i.e., operations Intro s b ( c 1 , c 2 ) \operatorname{Intro}_{\mathrm{sb}}(c_1,c_2) Intro sb ( c 1 , c 2 ) ) in the order that the corresponding events were executed. An edge e 1 → s b e 2 e_1 \xrightarrow{\mathrm{sb}} e_2 e 1 sb e 2 may be introduced long after e 1 e_1 e 1 and e 2 e_2 e 2 were introduced. Until then, we call the edge pending , and neither of the colors of e 1 e_1 e 1 and e 2 e_2 e 2 may be forgotten. We make this intuition precise next.
States. A state of A S k A_{\mathrm{S}}^{k} A S k is a tuple ⟨ P C , Φ , Q p n d , γ ⟩ \langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle ⟨ PC , Φ , Q pnd , γ ⟩ . Here, P C : T i d → N \mathrm{PC}\colon\mathrm{Tid}\to\mathbb{N} PC : Tid → N and Φ : R e g → V a l ∪ { ⊥ } \Phi\colon\mathrm{Reg}\to\mathrm{Val}\cup\{\perp\} Φ : Reg → Val ∪ { ⊥ } are the program counters and the store, as in the standard program semantics (Section A.1). Q p n d ⊆ [ k + 1 ] × [ k + 1 ] Q_{\mathrm{pnd}}\subseteq[k+1]\times[k+1] Q pnd ⊆ [ k + 1 ] × [ k + 1 ] is the set of pending sb edges. Since the word is canonical, the sb-predecessor of a new event of thread t t t is the most recent event of t t t . Q p n d Q_{\mathrm{pnd}} Q pnd records these edges until they are drawn, and thereby ensures that the word draws exactly the sb-edges of the program order. Finally, γ : T i d → [ k + 1 ] ∪ { ⊥ } \gamma\colon\mathrm{Tid}\to[k+1]\cup\{\perp\} γ : Tid → [ k + 1 ] ∪ { ⊥ } maps each thread to the color of its last event, or to ⊥ \perp ⊥ if that event is uncolored or does not exist. This information is used to create the pending edge of the next event of t t t . In the initial state, every program counter is 1 1 1 , every register holds ⊥ \perp ⊥ , Q p n d Q_{\mathrm{pnd}} Q pnd is empty, and γ \gamma γ maps every thread to ⊥ \perp ⊥ . All states are accepting.
Transition rules. We give a high-level description of the transition rules of A S k A_{\mathrm{S}}^{k} A S k , together with a few examples. The full set of rules appears in Section F.2.
Silent transitions (corresponding, e.g., to the execution of a local assignment d : = exp d:=\exp d := exp ) behave identically to the standard operational semantics (Section A.1), leaving the bookkeeping components Q p n d Q_{\mathrm{pnd}} Q pnd and γ \gamma γ unchanged. The operation Intro ( l a b , c ) \operatorname{Intro}(\mathrm{lab},c) Intro ( lab , c ) is emitted upon executing the instruction at P C ( t ) \mathrm{PC}(t) PC ( t ) for t = tid ( l a b ) t=\operatorname{tid}(\mathrm{lab}) t = tid ( lab ) . It adds the pending edge ⟨ γ ( t ) , c ⟩ \langle\gamma(t),c\rangle ⟨ γ ( t ) , c ⟩ if γ ( t ) ≠ ⊥ \gamma(t)\ne\perp γ ( t ) = ⊥ , which we write Q p n d ′ = PEND ( Q p n d , γ , t , c ) Q'_{\mathrm{pnd}}=\operatorname{PEND}(Q_{\mathrm{pnd}},\gamma,t,c) Q pnd ′ = PEND ( Q pnd , γ , t , c ) , and sets γ ( t ) \gamma(t) γ ( t ) to c c c . For example, the rule for a read takes the value v v v from the label, and stores it in the register:
o p = Intro ( l a b , c ) l a b = r a ( t , x , v ) S t ( P C ( t ) ) = d : = a x P C ′ = P C [ t ↦ P C ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] Q p n d ′ = PEND ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ P C , Φ , Q p n d , γ ⟩ → o p ⟨ P C ′ , Φ ′ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
\mathrm{op}&=\operatorname{Intro}(\mathrm{lab},c) & \mathrm{lab}&=r_a(t,x,v) & S_t(\mathrm{PC}(t))&=d:=a\ x \\
\mathrm{PC}'&=\mathrm{PC}[t\mapsto\mathrm{PC}(t)+1] & \Phi'&=\Phi[d\mapsto v] & Q'_{\mathrm{pnd}}&=\operatorname{PEND}(Q_{\mathrm{pnd}},\gamma,t,c) & \gamma'&=\gamma[t\mapsto c] \\
\langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle&\xrightarrow{\mathrm{op}}\langle\mathrm{PC}',\Phi',Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op PC ′ ⟨ PC , Φ , Q pnd , γ ⟩ = Intro ( lab , c ) = PC [ t ↦ PC ( t ) + 1 ] op ⟨ PC ′ , Φ ′ , Q pnd ′ , γ ′ ⟩ lab Φ ′ = r a ( t , x , v ) = Φ [ d ↦ v ] S t ( PC ( t )) Q pnd ′ = d := a x = PEND ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ]
The remaining rules handle the other operations. Intro s b ( c 1 , c 2 ) \operatorname{Intro}_{\mathrm{sb}}(c_1,c_2) Intro sb ( c 1 , c 2 ) requires that the sb edge is pending, and removes it from Q p n d Q_{\mathrm{pnd}} Q pnd . Forget ( c ) \operatorname{Forget}(c) Forget ( c ) , shown for c ∉ img ( γ ) c \notin\operatorname{img}(\gamma) c ∈ / img ( γ ) (else γ \gamma γ is reset), requires that c c c is not an endpoint of a pending edge, which could no longer be drawn. Finally, Intro r f \operatorname{Intro}_{\mathrm{rf}} Intro rf and Intro m b \operatorname{Intro}_{\mathrm{mb}} Intro mb simply self-loop, as they do not affect the execution of each thread in isolation.
op = Intro s b ( c 1 , c 2 ) op = Forget ( c ) op = Intro b ( c 1 , c 2 ) ⟨ c 1 , c 2 ⟩ ∈ Q p n d ⟨ c , ⋅ ⟩ , ⟨ ⋅ , c ⟩ ∉ Q p n d b ∈ { r f , m b } Q p n d ′ = Q p n d ∖ { ⟨ c 1 , c 2 ⟩ } c ∉ img ( γ ) ⟨ P C , Φ , Q p n d , γ ⟩ ⟶ ⟨ P C , Φ , Q p n d ′ , γ ⟩ ⟨ P C , Φ , Q p n d , γ ⟩ ⟶ ⟨ P C , Φ , Q p n d , γ ⟩ ⟨ P C , Φ , Q p n d , γ ⟩ ⟶ ⟨ P C , Φ , Q p n d , γ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}_{\mathrm{sb}}(c_1,c_2)
&&\operatorname{op}=\operatorname{Forget}(c)
&&\operatorname{op}=\operatorname{Intro}_{b}(c_1,c_2)\\
&\langle c_1,c_2\rangle\in Q_{\mathrm{pnd}}
&&\langle c,\cdot\rangle,\langle\cdot,c\rangle\notin Q_{\mathrm{pnd}}
&&b\in\{\mathrm{rf},\mathrm{mb}\}\\
&Q'_{\mathrm{pnd}}=Q_{\mathrm{pnd}}\setminus\{\langle c_1,c_2\rangle\}
&&c\notin\operatorname{img}(\gamma)
&&\\
&\langle PC,\Phi,Q_{\mathrm{pnd}},\gamma\rangle\longrightarrow\langle PC,\Phi,Q'_{\mathrm{pnd}},\gamma\rangle
&&\langle PC,\Phi,Q_{\mathrm{pnd}},\gamma\rangle\longrightarrow\langle PC,\Phi,Q_{\mathrm{pnd}},\gamma\rangle
&&\langle PC,\Phi,Q_{\mathrm{pnd}},\gamma\rangle\longrightarrow\langle PC,\Phi,Q_{\mathrm{pnd}},\gamma\rangle
\end{aligned} op = Intro sb ( c 1 , c 2 ) ⟨ c 1 , c 2 ⟩ ∈ Q pnd Q pnd ′ = Q pnd ∖ {⟨ c 1 , c 2 ⟩} ⟨ P C , Φ , Q pnd , γ ⟩ ⟶ ⟨ P C , Φ , Q pnd ′ , γ ⟩ op = Forget ( c ) ⟨ c , ⋅ ⟩ , ⟨ ⋅ , c ⟩ ∈ / Q pnd c ∈ / img ( γ ) ⟨ P C , Φ , Q pnd , γ ⟩ ⟶ ⟨ P C , Φ , Q pnd , γ ⟩ op = Intro b ( c 1 , c 2 ) b ∈ { rf , mb } ⟨ P C , Φ , Q pnd , γ ⟩ ⟶ ⟨ P C , Φ , Q pnd , γ ⟩
Searching for witnesses. Let M M MM M M be a prefix-closed memory model, and let ℓ ≜ p w S C + 3 \ell\triangleq\mathrm{pwSC}+3 ℓ ≜ pwSC + 3 . By Lemma 6.2 , if P P P is not robust against M M MM M M , then it has a witness G G G with c p w ( G ) ≤ ℓ \mathrm{cpw}(G)\leq\ell cpw ( G ) ≤ ℓ . By the canonical analogue of Lemma 4.1, G = G w G=G^w G = G w for some closed canonical w ∈ Ops ( ℓ + 1 ) ∗ w\in\operatorname{Ops}(\ell+1)^* w ∈ Ops ( ℓ + 1 ) ∗ . Together with Lemmas 5.1 , 5.3 and 6.3, this gives
P is robust against M M ⟺ L ( A w f ℓ ) ∩ L ( A l s ℓ ) ∩ L ( A M M ℓ ) ∩ L ( A ¬ S C ℓ ) = ∅ P\text{ is robust against }MM\Longleftrightarrow\mathcal{L}(\mathcal{A}^{\ell}_{\mathrm{wf}})\cap\mathcal{L}(\mathcal{A}^{\ell}_{\mathrm{ls}})\cap\mathcal{L}(\mathcal{A}^{\ell}_{MM})\cap\mathcal{L}(\mathcal{A}^{\ell}_{\neg\mathrm{SC}})=\varnothing P is robust against M M ⟺ L ( A wf ℓ ) ∩ L ( A ls ℓ ) ∩ L ( A M M ℓ ) ∩ L ( A ¬ SC ℓ ) = ∅
which is the characterization of § 5.4 , with A l s ℓ \mathcal{A}^{\ell}_{\mathrm{ls}} A ls ℓ in place of A P ℓ \mathcal{A}^{\ell}_{P} A P ℓ . A state of A l s ℓ \mathcal{A}^{\ell}_{\mathrm{ls}} A ls ℓ also has polynomial size, and its transitions can be verified in polynomial space, leading to the PSPACE bound. As A l s ℓ \mathcal{A}^{\ell}_{\mathrm{ls}} A ls ℓ executes the instructions of each thread in program order, the above automata can also be executed on the fly in a dynamic analysis setting, as, e.g., in [18 , 20 , 49 ] .
Undecidability of Robustness for Relaxed
In this section we prove Theorem 1.2 , thereby showing that the prefix-closedness condition of Theorem 1.1 cannot be dropped, in general.
The Relaxed memory model. Relaxed enforces SC per location. Formally, let
p o l o c ≜ ⋃ x ∈ L o c [ L a b x ] ; p o ; [ L a b x ] . \mathrm{poloc}\triangleq\bigcup_{x\in\mathrm{Loc}}[\mathrm{Lab}_x];\mathrm{po};[\mathrm{Lab}_x]. poloc ≜ x ∈ Loc ⋃ [ Lab x ] ; po ; [ Lab x ] .
Then R e l a x e d ≜ ( p o l o c ∪ r f ∪ m o ∪ f r ) + \mathrm{Relaxed}\triangleq(\mathrm{poloc}\cup\mathrm{rf}\cup\mathrm{mo}\cup\mathrm{fr})^+ Relaxed ≜ ( poloc ∪ rf ∪ mo ∪ fr ) + . Since each of these relations only connects events on the same location, every forbidden cycle stays on one location; thus Relaxed allows ( p o ∪ r f ) (\mathrm{po}\cup\mathrm{rf}) ( po ∪ rf ) -cycles.
A tight undecidability of reachability. State reachability under M M MM M M asks, given a concurrent program P P P and a state s t s_t s t of each P s e q t P\mathrm{seq}_t P seq t , whether some G ∈ ⟦ P ⟧ M M G\in\llbracket P\rrbracket_{MM} G ∈ [ [ P ] ] M M brings each thread t t t to s t s_t s t , i.e., P s e q t P\mathrm{seq}_t P seq t has a run on the word of t t t in G G G that ends in s t s_t s t . Equivalently, we may add to each P s e q t P\mathrm{seq}_t P seq t a transition from s t s_t s t that emits a special event t e r m \mathrm{term} term , which accesses no location, and ask whether some G G G reaches t e r m \mathrm{term} term , i.e., every thread has a t e r m \mathrm{term} term event in G G G . We prove the following theorem.
Theorem 7.1. State reachability under Relaxed is undecidable, already over programs with two threads and two memory locations.
Note that, over a single location, we have p o l o c = p o \mathrm{poloc}=\mathrm{po} poloc = po , and thus Relaxed coincides with SC. Similarly, over a single thread, Relaxed coincides with SC. This is because p o \mathrm{po} po is total, so every r f \mathrm{rf} rf -, m o \mathrm{mo} mo - or f r \mathrm{fr} fr -edge goes p o \mathrm{po} po -forward, as it would otherwise close a p o l o c \mathrm{poloc} poloc -cycle, and so every cycle of p o ∪ r f ∪ m o ∪ f r \mathrm{po}\cup\mathrm{rf}\cup\mathrm{mo}\cup\mathrm{fr} po ∪ rf ∪ mo ∪ fr is a p o \mathrm{po} po -cycle. Since reachability for SC is decidable (PSPACE-complete [39 , 66 ] ), Theorem 7.1 gives a tight dichotomy on the decidability of reachability for Relaxed with respect to each parameter4 .
Undecidability of robustness. We now prove Theorem 1.2 via a reduction from state reachability, and relying on Theorem 7.1 . We remark that such a reduction is not always possible, e.g., RA has undecidable reachability [1 , 23 ] but decidable robustness [44 ] (also, Theorem 1.1 ). Intuitively, such a reduction is possible for Relaxed because the model allows for unconstrained ( p o ∪ r f ) (\mathit{po} \cup\mathit{rf}) ( po ∪ rf ) -cycles.5
Consider a two-threaded program P = ⟨ P s e q t 1 , P s e q t 2 ⟩ P = \langle P_{\mathrm{seq}_{t_1}}, P_{\mathrm{seq}_{t_2}}\rangle P = ⟨ P seq t 1 , P seq t 2 ⟩ in which term is the last statement of each thread, and the reachability problem of determining whether term is reachable via a Relaxed execution. Let P ′ P' P ′ extend P P P with two fresh locations x x x and y y y , as shown on the right. Note that each thread can execute its if block iff the other thread executes its last write. This results in a ( p o ∪ r f ) (\mathit{po} \cup\mathit{rf}) ( po ∪ rf ) -cycle, which makes the execution impossible under SC. On the other hand, Relaxed allows this cycle (in practice, this could be due to speculation). We thus have that P ′ P' P ′ is not robust against Relaxed iff P P P reaches term on both threads. Intuitively, the lack of prefix-closedness implies that the smallest pathwidth of a witness might be arbitrarily large. Here, it is the pathwidth of the execution that brings P P P to term , plus a constant, and the former is unbounded.
Thread t₁ Thread t₂
if x = 1 then if y = 1 then
Pseqₜ₁ Pseqₜ₂
y := 1 x := 1
Lemma 7.2. For every concurrent program P P P with two threads, P ′ P' P ′ is robust against Relaxed iff no G ∈ ⟦ P ⟧ R e l a x e d G \in\llbracket P \rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P ] ] Relaxed reaches term .
Experiments
Here we report on an implementation of our algorithm behind Theorem 1.1 in a prototype tool RoboKAT, and an experimental evaluation on a range of memory models.
Implementation. RoboKAT is implemented inside the Spin model checker [35 ] . Its inputs are a program (as in § 2.3 ) and a KAT-defined memory model. Both are compiled into an instrumented Promela program that implements the sequential monitor of § 6 . RoboKAT further detects and removes color symmetries, thereby collapsing monitor states that are equal up to recoloring. Robustness violation witnesses are reported through Spin trails.
Benchmarks and memory models. We experiment with a range of memory models, with their KAT definitions as listed in Section B, on benchmarks across four categories:
Classic litmus tests from the literature, whose accesses all have the same access mode, checked against TSO, PSO, SRA, RA, WRA6 and PSI, as these models do not mix accesses.
Litmus tests with accesses of mixed modes, checked against RC11 and RC20.
Litmus tests from the OCaml memory model repository [51 ] , checked against OCaml.
The benchmarks of Rocker [44 ] , checked against TSO and RA, as in the corresponding paper.
Setup. We run RoboKAT using Spin 6.5.2 and gcc -O2, single-threaded. We use an Intel Xeon Platinum 8168 machine with 192 GB of RAM, running Debian. For the more demanding benchmarks, we enable state hashing in Spin, which stores 64-bit hashes instead of concrete states. We report the running time for each benchmark in seconds.
Results. Table 1 lists the results on the first benchmark category, with ✓ and × reporting a robust and non-robust program, respectively. The verdicts are consistent with the relative strength of the models, with more violations reported on weaker models. SB is the canonical example of weak behaviors and is non-robust against all models of Table 1 . MP exhibits a standard message-passing pattern that is robust against all models that preserve the order of writes; PSO does not, as it reorders writes to different locations. LB has a weak behavior involving ( p o ∪ r f ) (\mathit{po} \cup\mathit{rf}) ( po ∪ rf ) -cycles, which are disallowed by all models, and thus is found robust against all. R separates PSI from SRA, intuitively because in PSI, m o \mathrm{mo} mo also propagates causality (similarly for WRW+WR and WRR+2W). Notably, R is not robust against TSO, while IRIW is robust against TSO but not against PSI, which shows that the two models are incomparable.
Table 1. Litmus tests without mixed access modes.
Table 2 lists the results of the second category, with NA marking a non-applicable benchmark due to sc accesses that RC20 lacks. The robustness checks agree between RC11 and RC20 on every test except MP+relseq+acq. This is because, in RC11, an acquire read r ( x ) r(x) r ( x ) synchronizes with a release write w 1 ( x ) w_1(x) w 1 ( x ) even if r ( x ) r(x) r ( x ) reads from a write w 2 ( x ) w_2(x) w 2 ( x ) with w 1 ( x ) → w 2 ( x ) w_1(x) \to w_2(x) w 1 ( x ) → w 2 ( x ) ; in contrast, RC20 mirrors the C++20 change [16 ] , where release sequences go only along RMW chains.
Table 2. Litmus tests with mixed access modes.
Table 3 lists the results on OCaml. Here, every location is either atomic, which behaves like SC, or non-atomic, which behaves very weakly, e.g., without read-read coherence. The robustness checks showcase this split. E.g., IRIW is robust when both locations are atomic (IRIWaa), but not when one of them is non-atomic (IRIWan), and CoRR+W+ponns exhibits a read-read coherence violation.
Table 3. Litmus tests for OCaml.
Across all three tables, the total runtime is in the order of seconds, with compilation taking up 84% of the time, on average. Of the remaining 16%, about 10% is spent on generating Promela code from the input, and only 6% in Spin for robustness checking (the median is 0.12s).
Finally, we discuss Table 4 on the Rocker benchmarks, which are bigger and more challenging. Here, the relative time for robustness checking increases up to 81%, dominating the total time.
Table 4. Benchmarks of Rocker.
RoboKAT catches all violations reported by Rocker (for RA) and Trencher (for TSO) in [44 Fig. 7] , but manages to prove robust only barrier (against both RA and TSO) and peterson-tso (against TSO). (†) marks the instances where state hashing was turned on. Rocker has 15 more benchmarks that are robust and not shown here; RoboKAT times out on them after 1h (with state hashing).
Related Work
Here we discuss related literature beyond the work on robustness covered in § 1 .
Data-race freedom. A common syntactic approximation to robustness is data-race freedom (DRF) [3 , 4 , 34 ] , where a program free of certain types of races is guaranteed to observe only SC behaviors. DRF holds for various models, such as TSO [53 ] , C/C++ [13 , 15 , 45 ] , Java [48 ] , OCaml [32 ] and Wasm [57 ] , but it is known to be too conservative, as racy programs can still be robust.
Fences. When a program is not robust, it can be made so by inserting fences that restrict the reordering of its memory accesses [64 ] . As fences incur a runtime overhead [7 ] , much work aims to optimize fence placement for various hardware models [2 , 7 , 9 , 18 ] . For language-level models, [43 ] proposes syntactic criteria for fences that restore SC under SRA, and [52 ] proposes a dynamic-analysis approach for strengthening C/C++ memory accesses to recover SC. As our robustness checker is parametric in the memory model, it can serve as an exact oracle for fence placement across these settings. Fences also arise in compilation mappings between memory models [45 , 54 , 59 , 62 ] , which act conservatively as they must be correct for all programs.
Treewidth in concurrency. Our approach follows the recipe behind Courcelle’s theorem [25 ] , with KAT in place of MSO and pathwidth in place of treewidth, which yields automata of single-exponential rather than non-elementary size. For automata with stacks and queues, Courcelle’s result enables decidable under-approximations of reachability, by restricting to behaviors of bounded treewidth [47 , 68 ] or split-width [28 ] . The corresponding languages were recently shown to coincide with the MCFLs [5 ] . Similarly, message-passing communication models are MSO-definable, so model checking is decidable as an under-approximation over behaviors of bounded special treewidth [31 ] . The notion closest to robustness is synchronizability, which asks whether all behaviors of a message-passing system lie in a well-behaved class. It is decidable when this class is artificially restricted to bounded special treewidth, via a generic MSO procedure with non-elementary complexity. Equivalence to synchronous communication is, however, undecidable [17 , 33 ] . For robustness, in contrast, the target class is the natural SC, whose pathwidth is always bounded (Lemma 3.2), and we decide it exactly and uniformly in PSPACE. Finally, treewidth and MSO were recently used as a framework for weak-memory verification, partly also tackling the coarser notion of reads-from robustness [22 ] .
Conclusion
We have developed a generic algorithm for deciding robustness against any prefix-closed, KAT-definable memory model, in PSPACE. Our algorithm unifies a plethora of earlier, individual results on robustness, and also tackles several new memory models. We have further shown that the prefix-closedness condition cannot be dropped, in general. A natural next step is to tackle dependency-based models, such as POWER [10 ] , Armv8 [56 ] , RISC-V [60 ] and IMM [54 ] . The challenge here is that executions have richer signatures, which, if represented naively, break the bounded pathwidth of SC (Lemma 3.2). Another step is to handle memory models beyond KAT, e.g., those containing intersections or differences nested within other operators, as in LKMM [8 ] . Finally, RoboKAT is a prototype that leaves ample room for further engineering optimizations.
Acknowledgments
This work was partially supported by VILLUM FONDEN research grant VIL42117, the Independent Research Foundation of Denmark grant 5251-00076B, and the Swedish Research Council (VR) grant 2023-05242.
Disclosure of AI Use
We have used Claude AI for our Lean formalization. This was done post-factum, based on our paper proofs. We have also used Claude AI and ChatGPT in the development of RoboKAT and experimental setup in § 8 . All results were cross-checked for correctness.
References
Details of SEC:PRELIM
Program Semantics
Fix t ∈ T i d t \in\mathrm{Tid} t ∈ Tid and an instruction sequence S t : [ n t ] → I n s t S_t : [n_t] \to\mathrm{Inst} S t : [ n t ] → Inst . This subsection defines the LTS P s e q t \mathrm{Pseq}_t Pseq t that S t S_t S t induces (§ 2.3 ). The transitions of P s e q t \mathrm{Pseq}_t Pseq t from a state ⟨ p c , ϕ ⟩ \langle\mathrm{pc}, \phi\rangle ⟨ pc , ϕ ⟩ with p c ∈ [ n t ] \mathrm{pc} \in[n_t] pc ∈ [ n t ] are given by the rules below; a state with p c = n t + 1 \mathrm{pc} = n_t + 1 pc = n t + 1 has terminated and has no outgoing transition. In the rules, a target program counter outside [ n t ] [n_t] [ n t ] stands for n t + 1 n_t + 1 n t + 1 . Each rule applies only when the expressions it evaluates are not ⊥ \perp ⊥ ; we leave this premise implicit. A failed CAS does not evaluate exp W \exp_W exp W .
A failed CAS reads without writing, so it emits a read label. To let memory models tell this read apart from the read of a read instruction, we assume that, for every annotation a a a carried by an instruction, A n n \mathrm{Ann} Ann contains a sibling annotation a ‾ \overline{a} a , which no instruction carries and only failed CAS operations emit. Tests compare annotations up to siblings, i.e., a condition a n n ( l a b ) = a \mathrm{ann}(\mathrm{lab}) = a ann ( lab ) = a in a test stands for a n n ( l a b ) ∈ { a , a ‾ } \mathrm{ann}(\mathrm{lab}) \in\{a, \overline{a}\} ann ( lab ) ∈ { a , a } . For example, { l a b ∈ L a b : a n n ( l a b ) = r l x } \{\mathrm{lab} \in\mathrm{Lab}: \mathrm{ann}(\mathrm{lab}) = \mathrm{rlx}\} { lab ∈ Lab : ann ( lab ) = rlx } also contains the reads of failed rlx CAS operations. So, by default, a failed CAS behaves as a read with the annotation of its instruction. A model may still single out failed CAS operations with the test F C A S ≜ { l a b ∈ L a b : a n n ( l a b ) = a ‾ for some a ∈ A n n } \mathrm{FCAS} \triangleq\{\mathrm{lab} \in\mathrm{Lab}: \mathrm{ann}(\mathrm{lab}) = \overline{a}\text{ for some }a \in\mathrm{Ann}\} FCAS ≜ { lab ∈ Lab : ann ( lab ) = a for some a ∈ Ann } . This assumption at most doubles ∣ A n n ∣ |\mathrm{Ann}| ∣ Ann ∣ .
The first four rules are silent, and the others emit the label of an event of t t t .
S t ( p c ) = d : = exp ⟨ p c , ϕ ⟩ → ϵ ⟨ p c + 1 , ϕ [ d ↦ ϕ ( exp ) ] ⟩ \frac{S_t(\mathrm{pc}) = d := \exp}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\epsilon} \langle\mathrm{pc} + 1, \phi[d \mapsto\phi(\exp)] \rangle} ⟨ pc , ϕ ⟩ ϵ ⟨ pc + 1 , ϕ [ d ↦ ϕ ( exp )]⟩ S t ( pc ) = d := exp
S t ( p c ) = d : = N D e t ( V a l ′ ) v ∈ V a l ′ ⟨ p c , ϕ ⟩ → ϵ ⟨ p c + 1 , ϕ [ d ↦ v ] ⟩ \frac{S_t(\mathrm{pc}) = d := \mathrm{NDet}(\mathrm{Val}') \qquad v \in\mathrm{Val}'}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\epsilon} \langle\mathrm{pc} + 1, \phi[d \mapsto v] \rangle} ⟨ pc , ϕ ⟩ ϵ ⟨ pc + 1 , ϕ [ d ↦ v ]⟩ S t ( pc ) = d := NDet ( Val ′ ) v ∈ Val ′
S t ( p c ) = i f exp g o t o m ϕ ( exp ) ≠ 0 ⟨ p c , ϕ ⟩ → ϵ ⟨ m , ϕ ⟩ \frac{S_t(\mathrm{pc}) = \mathrm{if}\ \exp\ \mathrm{goto}\ m \qquad\phi(\exp) \ne0}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\epsilon} \langle m, \phi\rangle} ⟨ pc , ϕ ⟩ ϵ ⟨ m , ϕ ⟩ S t ( pc ) = if exp goto m ϕ ( exp ) = 0
S t ( p c ) = i f exp g o t o m ϕ ( exp ) = 0 ⟨ p c , ϕ ⟩ → ϵ ⟨ p c + 1 , ϕ ⟩ \frac{S_t(\mathrm{pc}) = \mathrm{if}\ \exp\ \mathrm{goto}\ m \qquad\phi(\exp) = 0}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\epsilon} \langle\mathrm{pc} + 1, \phi\rangle} ⟨ pc , ϕ ⟩ ϵ ⟨ pc + 1 , ϕ ⟩ S t ( pc ) = if exp goto m ϕ ( exp ) = 0
S t ( p c ) = x : = a exp ⟨ p c , ϕ ⟩ → w a ( t , x , ϕ ( exp ) ) ⟨ p c + 1 , ϕ ⟩ \frac{S_t(\mathrm{pc}) = x :=_a \exp}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{w_a(t,x,\phi(\exp))} \langle\mathrm{pc} + 1, \phi\rangle} ⟨ pc , ϕ ⟩ w a ( t , x , ϕ ( e x p )) ⟨ pc + 1 , ϕ ⟩ S t ( pc ) = x : = a exp
S t ( p c ) = f e n c e a ⟨ p c , ϕ ⟩ → f a ( t ) ⟨ p c + 1 , ϕ ⟩ \frac{S_t(\mathrm{pc}) = \mathrm{fence}_a}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{f_a(t)} \langle\mathrm{pc} + 1, \phi\rangle} ⟨ pc , ϕ ⟩ f a ( t ) ⟨ pc + 1 , ϕ ⟩ S t ( pc ) = fence a
S t ( p c ) = d : = a x v ∈ V a l ⟨ p c , ϕ ⟩ → r a ( t , x , v ) ⟨ p c + 1 , ϕ [ d ↦ v ] ⟩ \frac{S_t(\mathrm{pc}) = d :=_a x \qquad v \in\mathrm{Val}}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{r_a(t,x,v)} \langle\mathrm{pc} + 1, \phi[d \mapsto v] \rangle} ⟨ pc , ϕ ⟩ r a ( t , x , v ) ⟨ pc + 1 , ϕ [ d ↦ v ]⟩ S t ( pc ) = d : = a x v ∈ Val
S t ( p c ) = d : = a C A S ( x , exp R , exp W ) v ∈ V a l ∖ { ϕ ( exp R ) } ⟨ p c , ϕ ⟩ → r ‾ a ( t , x , v ) ⟨ p c + 1 , ϕ [ d ↦ v ] ⟩ \frac{S_t(\mathrm{pc}) = d :=_a \mathrm{CAS}(x,\exp_R,\exp_W) \qquad v \in\mathrm{Val} \setminus\{\phi(\exp_R)\}}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\overline{r}_a(t,x,v)} \langle\mathrm{pc} + 1, \phi[d \mapsto v] \rangle} ⟨ pc , ϕ ⟩ r a ( t , x , v ) ⟨ pc + 1 , ϕ [ d ↦ v ]⟩ S t ( pc ) = d : = a CAS ( x , exp R , exp W ) v ∈ Val ∖ { ϕ ( exp R )}
S t ( p c ) = d : = a C A S ( x , exp R , exp W ) ⟨ p c , ϕ ⟩ → r m w a ( t , x , ϕ ( exp R ) , ϕ ( exp W ) ) ⟨ p c + 1 , ϕ [ d ↦ ϕ ( exp R ) ] ⟩ \frac{S_t(\mathrm{pc}) = d :=_a \mathrm{CAS}(x,\exp_R,\exp_W)}{\langle\mathrm{pc}, \phi\rangle\xrightarrow{\mathrm{rmw}_a(t,x,\phi(\exp_R),\phi(\exp_W))} \langle\mathrm{pc} + 1, \phi[d \mapsto\phi(\exp_R)] \rangle} ⟨ pc , ϕ ⟩ rmw a ( t , x , ϕ ( e x p R ) , ϕ ( e x p W )) ⟨ pc + 1 , ϕ [ d ↦ ϕ ( exp R )]⟩ S t ( pc ) = d : = a CAS ( x , exp R , exp W )
A read may observe any value v v v , and a failed CAS any value other than ϕ ( exp R ) \phi(\exp_R) ϕ ( exp R ) ; which value is observed is determined by the r f \mathrm{rf} rf -edge of its event, not by P s e q t \mathrm{Pseq}_t Pseq t . Let ∣ S t ∣ |S_t| ∣ S t ∣ be the total number of symbols in the instructions of S t S_t S t , counting the expressions and the sets V a l ′ \mathrm{Val}' Val ′ of N D e t ( V a l ′ ) \mathrm{NDet}(\mathrm{Val}') NDet ( Val ′ ) . We assume that each binary operator on V a l \mathrm{Val} Val is evaluated in constant time, e.g., by a lookup table. Then, given two states ⟨ p c , ϕ ⟩ \langle\mathrm{pc}, \phi\rangle ⟨ pc , ϕ ⟩ and ⟨ p c ′ , ϕ ′ ⟩ \langle\mathrm{pc}', \phi' \rangle ⟨ pc ′ , ϕ ′ ⟩ and a label ϵ \epsilon ϵ , whether they form a transition of P s e q t \mathrm{Pseq}_t Pseq t is decidable in time O ( ∣ S t ∣ + ∣ R e g t ∣ ) O(|S_t| + |\mathrm{Reg}_t|) O ( ∣ S t ∣ + ∣ Reg t ∣ ) . To check this, we evaluate the at most two expressions of S t ( p c ) S_t(\mathrm{pc}) S t ( pc ) under ϕ \phi ϕ , in time O ( ∣ S t ( p c ) ∣ ) O(|S_t(\mathrm{pc})|) O ( ∣ S t ( pc ) ∣ ) . For N D e t ( V a l ′ ) \mathrm{NDet}(\mathrm{Val}') NDet ( Val ′ ) , we also check v ∈ V a l ′ v \in\mathrm{Val}' v ∈ Val ′ , in time O ( ∣ V a l ′ ∣ ) O(|\mathrm{Val}'|) O ( ∣ Val ′ ∣ ) , where ∣ V a l ′ ∣ ≤ ∣ S t ∣ |\mathrm{Val}'| \le|S_t| ∣ Val ′ ∣ ≤ ∣ S t ∣ . Finally, we compare the label and p c ′ \mathrm{pc}' pc ′ , and compare ϕ ′ \phi' ϕ ′ with the updated store register by register, in time O ( ∣ R e g t ∣ ) O(|\mathrm{Reg}_t|) O ( ∣ Reg t ∣ ) .
Compiling KAT Expressions
In this subsection, we prove Lemma 2.1. We build K φ \mathcal{K}_{\varphi} K φ by induction on φ \varphi φ , as for regular expressions. Throughout, K φ \mathcal{K}_{\varphi} K φ has a single accepting state q f ≠ i n i t q_f \ne\mathrm{init} q f = init , i.e., Q F = { q f } Q_F = \{q_f\} Q F = { q f } , and no transition enters i n i t \mathrm{init} init or leaves q f q_f q f .
A transition labeled by the test L a b \mathrm{Lab} Lab behaves like a silent transition, as it is realized exactly by staying at any event.
Constructions. The cases of the induction are the following.
Tests and base relations. For a test [ τ ] [\tau] [ τ ] or a base relation symbol b b b , K φ \mathcal{K}_{\varphi} K φ is the single transition i n i t → τ q f \mathrm{init} \xrightarrow{\tau} q_f init τ q f or i n i t → b q f \mathrm{init} \xrightarrow{b} q_f init b q f , respectively.
Union. For φ 1 ∪ φ 2 \varphi_1 \cup\varphi_2 φ 1 ∪ φ 2 , take K φ 1 \mathcal{K}_{\varphi_1} K φ 1 and K φ 2 \mathcal{K}_{\varphi_2} K φ 2 , and merge their initial states and their accepting states.
Composition. For φ 1 ; φ 2 \varphi_1;\varphi_2 φ 1 ; φ 2 , take K φ 1 \mathcal{K}_{\varphi_1} K φ 1 and K φ 2 \mathcal{K}_{\varphi_2} K φ 2 , and merge the accepting state of K φ 1 \mathcal{K}_{\varphi_1} K φ 1 with the initial state of K φ 2 \mathcal{K}_{\varphi_2} K φ 2 .
Transitive closure. For φ + \varphi^{+} φ + , take K φ \mathcal{K}_{\varphi} K φ , with initial state p p p and accepting state p ′ p^{\prime} p ′ , and add a fresh initial state i n i t \mathrm{init} init , a fresh accepting state q f q_f q f , and the transitions i n i t → L a b p \mathrm{init} \xrightarrow{\mathrm{Lab}} p init Lab p , p , p ′ → L a b p p,p^{\prime} \xrightarrow{\mathrm{Lab}} p p , p ′ Lab p and p ′ → L a b q f p^{\prime} \xrightarrow{\mathrm{Lab}} q_f p ′ Lab q f .
Inverse. For φ − 1 \varphi^{-1} φ − 1 , reverse every transition of K φ \mathcal{K}_{\varphi} K φ , swap i n i t \mathrm{init} init and q f q_f q f , and replace each base relation symbol b b b by b − 1 b^{-1} b − 1 , where ( b − 1 ) − 1 = b (b^{-1})^{-1} = b ( b − 1 ) − 1 = b . Tests are unchanged.
Each construction keeps a single initial state and a single accepting state, which are distinct, with no transition entering the former or leaving the latter. This is what allows us to merge states in the union and the composition, without creating new runs.
Lemma 2.1 ([41]). For every KAT expression φ \varphi φ , there is a KAT-NFA K φ \mathcal{K}_{\varphi} K φ with O ( ∣ φ ∣ ) O(|\varphi|) O ( ∣ φ ∣ ) states and transitions, constructible in time O ( ∣ φ ∣ ) O(|\varphi|) O ( ∣ φ ∣ ) , such that, for every execution graph G G G and e , e ′ ∈ G . E e,e^{\prime} \in G.E e , e ′ ∈ G . E , we have ⟨ e , e ′ ⟩ ∈ G . φ \langle e,e^{\prime}\rangle\in G.\varphi ⟨ e , e ′ ⟩ ∈ G . φ iff some w ∈ L ( K φ ) w \in L(\mathcal{K}_{\varphi}) w ∈ L ( K φ ) has a realization in G G G from e e e to e ′ e^{\prime} e ′ .
Proof. We first show, by induction on φ \varphi φ , that K φ \mathcal{K}_{\varphi} K φ has at most 2 ∣ φ ∣ + 2 2|\varphi| + 2 2∣ φ ∣ + 2 states and 3 ∣ φ ∣ 3|\varphi| 3∣ φ ∣ transitions.
Tests and base relations. K φ \mathcal{K}_{\varphi} K φ has 2 ≤ 2 ∣ φ ∣ + 2 2 \le2|\varphi| + 2 2 ≤ 2∣ φ ∣ + 2 states and 1 ≤ 3 ∣ φ ∣ 1 \le3|\varphi| 1 ≤ 3∣ φ ∣ transitions.
Union and composition. Both merge states of K φ 1 \mathcal{K}_{\varphi_1} K φ 1 and K φ 2 \mathcal{K}_{\varphi_2} K φ 2 , so they have at most 2 ∣ φ 1 ∣ + 2 ∣ φ 2 ∣ + 4 ≤ 2 ∣ φ ∣ + 2 2|\varphi_1| + 2|\varphi_2| + 4 \le2|\varphi| + 2 2∣ φ 1 ∣ + 2∣ φ 2 ∣ + 4 ≤ 2∣ φ ∣ + 2 states and 3 ∣ φ 1 ∣ + 3 ∣ φ 2 ∣ ≤ 3 ∣ φ ∣ 3|\varphi_1| + 3|\varphi_2| \le3|\varphi| 3∣ φ 1 ∣ + 3∣ φ 2 ∣ ≤ 3∣ φ ∣ transitions, as ∣ φ ∣ = ∣ φ 1 ∣ + ∣ φ 2 ∣ + 1 |\varphi| = |\varphi_1| + |\varphi_2| + 1 ∣ φ ∣ = ∣ φ 1 ∣ + ∣ φ 2 ∣ + 1 .
Transitive closure. The construction adds two states and three transitions, and ∣ φ + ∣ = ∣ φ ∣ + 1 |\varphi^{+}| = |\varphi| + 1 ∣ φ + ∣ = ∣ φ ∣ + 1 .
Inverse. The construction adds no states and no transitions.
Each construction takes time linear in the number of states and transitions it adds, so K φ \mathcal{K}_{\varphi} K φ is constructed in time O ( ∣ φ ∣ ) O(|\varphi|) O ( ∣ φ ∣ ) .
Now fix an execution graph G G G . We show by induction on φ \varphi φ that ⟨ e , e ′ ⟩ ∈ G . φ \langle e,e^{\prime}\rangle\in G.\varphi ⟨ e , e ′ ⟩ ∈ G . φ iff some w ∈ L ( K φ ) w \in L(\mathcal{K}_{\varphi}) w ∈ L ( K φ ) has a realization in G G G from e e e to e ′ e^{\prime} e ′ .
Tests and base relations. This is the definition of a realization.
Union. An accepting run of K φ 1 ∪ φ 2 \mathcal{K}_{\varphi_1\cup\varphi_2} K φ 1 ∪ φ 2 stays in one of K φ 1 \mathcal{K}_{\varphi_1} K φ 1 and K φ 2 \mathcal{K}_{\varphi_2} K φ 2 , as no transition enters the initial states or leaves the accepting states. So, L ( K φ 1 ∪ φ 2 ) = L ( K φ 1 ) ∪ L ( K φ 2 ) L(\mathcal{K}_{\varphi_1\cup\varphi_2}) = L(\mathcal{K}_{\varphi_1}) \cup L(\mathcal{K}_{\varphi_2}) L ( K φ 1 ∪ φ 2 ) = L ( K φ 1 ) ∪ L ( K φ 2 ) , and the claim follows from G . ( φ 1 ∪ φ 2 ) = G . φ 1 ∪ G . φ 2 G.(\varphi_1 \cup\varphi_2) = G.\varphi_1 \cup G.\varphi_2 G . ( φ 1 ∪ φ 2 ) = G . φ 1 ∪ G . φ 2 .
Composition. An accepting run of K φ 1 ; φ 2 \mathcal{K}_{\varphi_1;\varphi_2} K φ 1 ; φ 2 visits the merged state exactly once, so L ( K φ 1 ; φ 2 ) = L ( K φ 1 ) ⋅ L ( K φ 2 ) L(\mathcal{K}_{\varphi_1;\varphi_2}) = L(\mathcal{K}_{\varphi_1}) \cdot L(\mathcal{K}_{\varphi_2}) L ( K φ 1 ; φ 2 ) = L ( K φ 1 ) ⋅ L ( K φ 2 ) . Realizations of the concatenation w 1 w 2 w_1w_2 w 1 w 2 from e e e to e ′ e^{\prime} e ′ are exactly the realizations of w 1 w_1 w 1 from e e e to some e ′ ′ e^{\prime\prime} e ′′ , followed by realizations of w 2 w_2 w 2 from e ′ ′ e^{\prime\prime} e ′′ to e ′ e^{\prime} e ′ . So, the claim follows from G . ( φ 1 ; φ 2 ) = G . φ 1 ; G . φ 2 G.(\varphi_1;\varphi_2) = G.\varphi_1;G.\varphi_2 G . ( φ 1 ; φ 2 ) = G . φ 1 ; G . φ 2 .
Transitive closure. The words of L ( K φ + ) L(\mathcal{K}_{\varphi^{+}}) L ( K φ + ) are the words L a b w 1 L a b w 2 ⋯ L a b w k L a b \mathrm{Lab}\ w_1\ \mathrm{Lab}\ w_2 \cdots\mathrm{Lab}\ w_k\ \mathrm{Lab} Lab w 1 Lab w 2 ⋯ Lab w k Lab , for k ≥ 1 k \ge1 k ≥ 1 and w 1 , … , w k ∈ L ( K φ ) w_1,\ldots,w_k \in L(\mathcal{K}_{\varphi}) w 1 , … , w k ∈ L ( K φ ) . Each L a b \mathrm{Lab} Lab is realized by staying at the current event, so such a word
has a realization from e e e to e ′ e' e ′ iff there is a chain e = e 0 , … , e k = e ′ e=e_0,\ldots,e_k=e' e = e 0 , … , e k = e ′ with ⟨ e i − 1 , e i ⟩ ∈ G . φ \langle e_{i-1},e_i\rangle\in G.\varphi ⟨ e i − 1 , e i ⟩ ∈ G . φ for each i i i , i.e., iff ⟨ e , e ′ ⟩ ∈ ( G . φ ) + \langle e,e'\rangle\in(G.\varphi)^+ ⟨ e , e ′ ⟩ ∈ ( G . φ ) + .
Inverse. The words of L ( K φ − 1 ) \mathcal{L}(K_{\varphi^{-1}}) L ( K φ − 1 ) are the reversals of the words of L ( K φ ) \mathcal{L}(K_\varphi) L ( K φ ) , with each base relation symbol inverted. A realization of such a word from e e e to e ′ e' e ′ , read backwards, is a realization of the original word from e ′ e' e ′ to e e e , and vice versa. So, the claim follows from G . φ − 1 = ( G . φ ) − 1 G.\varphi^{-1}=(G.\varphi)^{-1} G . φ − 1 = ( G . φ ) − 1 .
Memory Models as KAT Expressions
In this section, we write several memory models of the literature as KAT expressions, and show that they are prefix-closed. Table 5 summarizes them. We first fix some notation and the axioms that several models share, then give a general sufficient condition for prefix-closedness, and finally treat each model in turn.
Table 5. The memory models of this section.
Non-atomic accesses. For the C11-style models RA, RC20, RC11 and WRC11, we omit non-atomic accesses, as these do not affect robustness unless they participate in a data race. Such races can be handled similarly to previous work [44 ] . First, we strengthen every non-atomic access to a release/acquire access, and check robustness with our procedure. A violation means that the original program is not robust. Otherwise, every consistent execution is SC-consistent, so the original program has a data race iff some reachable SC state is racy, which can be checked in PSPACE [39 , 66 ] .
Notation. Each axiom below is an irreflexivity constraint, and a model is the union of its axioms, as in § 2.4 . For an expression φ \varphi φ , we let φ ∣ l o c ≔ ⋃ x ∈ L o c [ L a b x ] ; φ ; [ L a b x ] \varphi|_{\mathrm{loc}}\coloneqq\bigcup_{x\in\mathrm{Loc}}[\mathrm{Lab}_x];\varphi;[\mathrm{Lab}_x] φ ∣ loc : = ⋃ x ∈ Loc [ Lab x ] ; φ ; [ Lab x ] be its restriction to pairs of events on the same location. For the C11-style models RC20 and RC11, the annotations are access modes A n n ⊆ { r l x , r e l , a c q , a c q - r e l , s c } \mathrm{Ann}\subseteq\{\mathrm{rlx},\mathrm{rel},\mathrm{acq},\mathrm{acq\text{-}rel},\mathrm{sc}\} Ann ⊆ { rlx , rel , acq , acq - rel , sc } , and we let L a b ⪰ r e l \mathrm{Lab}_{\succeq\mathrm{rel}} Lab ⪰ rel , L a b ⪰ a c q \mathrm{Lab}_{\succeq\mathrm{acq}} Lab ⪰ acq and L a b s c \mathrm{Lab}_{\mathrm{sc}} Lab sc be the labels annotated with rel, acq-rel or sc, with acq, acq-rel or sc, and with sc, respectively. As annotations are compared up to siblings (Section A.1), these sets also contain the reads of failed CAS operations with the respective modes, and likewise for the modes of reads, writes and fences in the models below.
Shared axioms. The following axioms are shared by several models.
m o ; h b \mathrm{mo};\mathrm{hb} mo ; hb
m o ; h b ; r f − 1 (read-coherence) m o ; m o ; r f − 1 (atomicity) ( h b ∪ m o ) + (strong-write-coherence) ⋃ x ∈ L o c h b ; [ W x ∪ R M W x ] ; h b ; [ L a b x ] ; r f − 1 (weak-read-coherence) m o ; [ R M W ] ; r f − 1 ; r f ; [ R M W ] (weak-atomicity) \begin{aligned}
\mathrm{mo};\mathrm{hb};\mathrm{rf}^{-1} &\qquad\text{(read-coherence)}\\
\mathrm{mo};\mathrm{mo};\mathrm{rf}^{-1} &\qquad\text{(atomicity)}\\
(\mathrm{hb}\cup\mathrm{mo})^{+} &\qquad\text{(strong-write-coherence)}\\
\bigcup_{x\in\mathrm{Loc}}\mathrm{hb};[\mathrm{W}_{x}\cup\mathrm{RMW}_{x}];\mathrm{hb};[\mathrm{Lab}_{x}];\mathrm{rf}^{-1} &\qquad\text{(weak-read-coherence)}\\
\mathrm{mo};[\mathrm{RMW}];\mathrm{rf}^{-1};\mathrm{rf};[\mathrm{RMW}] &\qquad\text{(weak-atomicity)}
\end{aligned} mo ; hb ; rf − 1 mo ; mo ; rf − 1 ( hb ∪ mo ) + x ∈ Loc ⋃ hb ; [ W x ∪ RMW x ] ; hb ; [ Lab x ] ; rf − 1 mo ; [ RMW ] ; rf − 1 ; rf ; [ RMW ] (read-coherence) (atomicity) (strong-write-coherence) (weak-read-coherence) (weak-atomicity)
In words, (irr-hb) forbids ( p o ∪ r f ) (\mathrm{po}\cup\mathrm{rf}) ( po ∪ rf ) -cycles, (write-coherence) requires m o \mathrm{mo} mo to agree with h b \mathrm{hb} hb , and (read-coherence) forbids a read from reading a write that is m o \mathrm{mo} mo -before another write h b \mathrm{hb} hb -before the read. (atomicity) forbids a write m o \mathrm{mo} mo -between an RMW and the write it reads from, (strong-write-coherence) requires h b ∪ m o \mathrm{hb}\cup\mathrm{mo} hb ∪ mo to be acyclic, (weak-read-coherence) forbids a write on x x x h b \mathrm{hb} hb -between a write and a read on x x x that reads from it, and (weak-atomicity) forbids two RMWs from reading the same write.
On the encoding of f r \mathrm{fr} fr . In this appendix, we distinguish the two definitions of f r \mathrm{fr} fr given in § 2.4 . We write f r ≔ ( r f − 1 ; m o ) ∖ i d \mathrm{fr}\coloneqq(\mathrm{rf}^{-1};\mathrm{mo})\setminus\mathrm{id} fr : = ( rf − 1 ; mo ) ∖ id for the standard from-read relation, and f r K A T ≔ [ R ] ; r f − 1 ; m o ∪ [ R M W ] ; r f − 1 ; m o ; m o \mathrm{fr}_{\mathrm{KAT}}\coloneqq[\mathrm{R}];\mathrm{rf}^{-1};\mathrm{mo}\cup[\mathrm{RMW}];\mathrm{rf}^{-1};\mathrm{mo};\mathrm{mo} fr KAT : = [ R ] ; rf − 1 ; mo ∪ [ RMW ] ; rf − 1 ; mo ; mo for its KAT definition. The axioms below are usually stated with f r \mathrm{fr} fr , and their KAT expressions use f r K A T \mathrm{fr}_{\mathrm{KAT}} fr KAT instead. We now show that this does not change the consistent graphs of the models we consider. The two relations agree on reads, as m o \mathrm{mo} mo only relates writes and RMWs. So, consider an RMW e e e that reads from an event e w e_{w} e w , both on a location x x x . As m o \mathrm{mo} mo totally orders the writes and RMWs on x x x , there are three cases.
e w m b e e_{w}\mathrel{\mathrm{mb}}e e w mb e . Then both f r \mathrm{fr} fr and f r K A T \mathrm{fr}_{\mathrm{KAT}} fr KAT relate e e e to exactly the events m o \mathrm{mo} mo -after e e e .
e w m o e ′ m o e e_{w}\mathrel{\mathrm{mo}}e'\mathrel{\mathrm{mo}}e e w mo e ′ mo e for some e ′ e' e ′ . This violates (atomicity), and we have e f r e ′ m o e e\mathrel{\mathrm{fr}}e'\mathrel{\mathrm{mo}}e e fr e ′ mo e and ⟨ e , e ⟩ ∈ f r K A T \langle e,e\rangle\in\mathrm{fr}_{\mathrm{KAT}} ⟨ e , e ⟩ ∈ fr KAT .
e m o e w e\mathrel{\mathrm{mo}}e_{w} e mo e w . Then e m o e w r f e e\mathrel{\mathrm{mo}}e_{w}\mathrel{\mathrm{rf}}e e mo e w rf e is a cycle of m o ; r f \mathrm{mo};\mathrm{rf} mo ; rf .
So, f r \mathrm{fr} fr and f r K A T \mathrm{fr}_{\mathrm{KAT}} fr KAT coincide in every graph that satisfies (atomicity) and in which m o ; r f \mathrm{mo};\mathrm{rf} mo ; rf is irreflexive. Hence, replacing f r \mathrm{fr} fr by f r K A T \mathrm{fr}_{\mathrm{KAT}} fr KAT in a model does not change its consistent graphs, as long as the model forbids, with either relation, the violations of (atomicity) and the cycles of m o ; r f \mathrm{mo};\mathrm{rf} mo ; rf . For example, SC forbids the cycles of r f ∪ m o ∪ f r \mathrm{rf}\cup\mathrm{mo}\cup\mathrm{fr} rf ∪ mo ∪ fr , and the last two cases yield such a cycle with either relation. RA, SRA, WRA, LRA and WRC11 do not use f r \mathrm{fr} fr , and RMWs do not occur in OCaml. For the other models, we show the condition along with their definitions.
Prefix-closedness. All the models of this section forbid ( p o ∪ r f ) (\mathrm{po}\cup\mathrm{rf}) ( po ∪ rf ) -cycles, and this suffices for prefix-closedness. We say that an expression φ \varphi φ uses m b \mathrm{mb} mb only through m o \mathrm{mo} mo if every occurrence of m b \mathrm{mb} mb and m b − 1 \mathrm{mb}^{-1} mb − 1 in φ \varphi φ , after expanding the derived relations, is in a subexpression m b + \mathrm{mb}^{+} mb + or ( m b − 1 ) + (\mathrm{mb}^{-1})^{+} ( mb − 1 ) + , respectively. This is the case for all the expressions of this section.
Lemma B.1. Let MM be a memory model that uses m b \mathrm{mb} mb only through m o \mathrm{mo} mo , and such that p o ∪ r f \mathrm{po}\cup\mathrm{rf} po ∪ rf is acyclic in every G ⊨ M M G\models\mathrm{MM} G ⊨ MM . Then MM is prefix-closed.
Proof. Let G = ⟨ E , s b , r f , m b ⟩ ⊨ M M G=\langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb}\rangle\models\mathrm{MM} G = ⟨ E , sb , rf , mb ⟩ ⊨ MM be non-empty. As p o ∪ r f \mathrm{po}\cup\mathrm{rf} po ∪ rf is acyclic and E E E is finite and non-empty, some event e e e has no outgoing p o \mathrm{po} po - or r f \mathrm{rf} rf -edge, so e e e is maximal. Let G ′ = G ∖ { e } G'=G\setminus\{e\} G ′ = G ∖ { e } . Moreover, as e e e has no outgoing s b \mathrm{sb} sb - or r f \mathrm{rf} rf -edge, G ′ . s b G'.\mathrm{sb} G ′ . sb , G ′ . p o G'.\mathrm{po} G ′ . po , G ′ . r f G'.\mathrm{rf} G ′ . rf and G ′ . m o G'.\mathrm{mo} G ′ . mo are the restrictions of G . s b G.\mathrm{sb} G . sb , G . p o G.\mathrm{po} G . po , G . r f G.\mathrm{rf} G . rf and G . m o G.\mathrm{mo} G . mo to E ∖ { e } E\setminus\{e\} E ∖ { e } , and so are their inverses. Every operator of KAT expressions is monotone, so, as MM uses m b \mathrm{mb} mb only through m o \mathrm{mo} mo , G ′ . M M ⊆ G . M M G'.\mathrm{MM}\subseteq G.\mathrm{MM} G ′ . MM ⊆ G . MM . Since G . M M G.\mathrm{MM} G . MM is irreflexive, so is G ′ . M M G'.\mathrm{MM} G ′ . MM , i.e., G ′ ⊨ M M G'\models\mathrm{MM} G ′ ⊨ MM . □ \square □
:::
Note that the condition on m b mb mb is needed, as removing e e e may create an m b mb mb -edge that skips over it. In particular, every model that contains (irr-hb), or another axiom whose expression contains h b = ( p o ∪ r f ) + hb = (po \cup rf)^{+} hb = ( p o ∪ r f ) + , is prefix-closed by Lemma B.1.
TSO and PSO. We take TSO from x86-TSO [63 ] , and PSO from the SPARC hierarchy of [6 ] . In both, a full fence (mfence on x86, membar on SPARC) is a fence annotated with sc, and we let F s c ≜ { l a b ∈ F : a n n ( l a b ) = s c } F_{\mathrm{sc}} \triangleq\{lab \in F: ann(lab) = sc\} F sc ≜ { l ab ∈ F : ann ( l ab ) = sc } . On x86, a CAS is a locked instruction, which acts as a full fence whether it succeeds or fails. So, the full barriers of TSO are F B ≜ F s c ∪ R M W ∪ F C A S FB \triangleq F_{\mathrm{sc}} \cup RMW \cup F_{\mathrm{CAS}} F B ≜ F sc ∪ R M W ∪ F CAS , where F C A S F_{\mathrm{CAS}} F CAS consists of the reads of failed CAS operations (Section A.1). For M M ∈ { T S O , P S O } MM \in\{TSO, PSO\} M M ∈ { T S O , P S O } , the derived relations are
p p o T S O ≜ [ R ] ; p o ∪ p o ; [ W ] ∪ [ F B ] ; p o ∪ p o ; [ F B ] + p p o P S O ≜ ( [ R ∪ R M W ] ; p o ) ∪ ( [ W ∪ R M W ] ; p o ; [ F s c ] ; p o ) g h b M M ≜ p p o M M ∪ r f e ∪ m o ∪ f r \begin{aligned}
ppo_{\mathrm{TSO}} &\triangleq[R];po \cup po;[W] \cup[FB];po \cup po;[FB]^{+} \\
ppo_{\mathrm{PSO}} &\triangleq([R \cup RMW];po) \cup([W \cup RMW];po;[F_{\mathrm{sc}}];po) \\
ghb_{MM} &\triangleq ppo_{MM} \cup rfe \cup mo \cup fr
\end{aligned} pp o TSO pp o PSO g h b M M ≜ [ R ] ; p o ∪ p o ; [ W ] ∪ [ F B ] ; p o ∪ p o ; [ F B ] + ≜ ([ R ∪ R M W ] ; p o ) ∪ ([ W ∪ R M W ] ; p o ; [ F sc ] ; p o ) ≜ pp o M M ∪ r f e ∪ m o ∪ f r
In words, p p o T S O ppo_{\mathrm{TSO}} pp o TSO preserves the program order between any two events, except from a write to a later read, unless one of the two is a full barrier or a full barrier lies between them. p p o P S O ppo_{\mathrm{PSO}} pp o PSO preserves the program order from every read and RMW, but orders a write before later events only through a full fence. The axioms are
( p o ∣ l o c ∪ r f ∪ m o ∪ f r ) + (po \mathbin{|}_{loc} \cup rf \cup mo \cup fr)^{+} ( p o ∣ l oc ∪ r f ∪ m o ∪ f r ) +
(uniproc)
g h b M M + ghb_{MM}^{+} g h b M M +
(ghb)
So, M M ≜ MM \triangleq M M ≜ (uniproc) ∪ \cup ∪ (ghb). As for SC, (uniproc) forbids the cycles of r f ∪ m o ∪ f r rf \cup mo \cup fr r f ∪ m o ∪ f r , and hence the violations of (atomicity) and the cycles of m o ; r f mo;rf m o ; r f , with either f r fr f r or f r K A T fr_{\mathrm{KAT}} f r KAT . Both models forbid ( p o ∪ r f ) (po \cup rf) ( p o ∪ r f ) -cycles. Indeed, such a cycle contains an r f e rfe r f e -edge, as r f rf r f -edges within a thread follow p o po p o by (uniproc). Between two consecutive r f e rfe r f e -edges, the cycle follows a p o po p o -path that starts at a read or an RMW, which is in p p o M M ppo_{MM} pp o M M . So, the cycle yields a cycle of g h b M M ghb_{MM} g h b M M , and TSO and PSO are prefix-closed by Lemma B.1.
RA. Following [43 , 44 ] , R A ≜ RA \triangleq R A ≜ (irr-hb) ∪ \cup ∪ (write-coherence) ∪ \cup ∪ (read-coherence) ∪ \cup ∪ (atomicity), as in § 2.4 .
SRA. Following [42 , 43 ] , S R A ≜ SRA \triangleq S R A ≜ (strong-write-coherence)∪ \cup ∪ (read-coherence)∪ \cup ∪ (atomicity). Without RMWs, SRA coincides with Causal Convergence [42 ] . As h b ⊆ ( h b ∪ m o ) + hb \subseteq(hb \cup mo)^{+} hb ⊆ ( hb ∪ m o ) + , it is prefix-closed by Lemma B.1.
WRA. WRA [42 ] is given by (irr-hb), (weak-read-coherence) and (weak-atomicity), and, without RMWs, it coincides with Causal Consistency [42 ] . These axioms do not constrain m o mo m o , apart from the distinctness of two RMWs in (weak-atomicity), which holds for either order of the two. In our setting, however, m b mb mb is part of every execution graph, and SC does constrain it. So, robustness against these three axioms alone is nearly trivial: if some SC-consistent graph P P P has two writes e 1 → p o e 2 e_1 \xrightarrow{po} e_2 e 1 p o e 2 on the same location, then swapping e 1 e_1 e 1 and e 2 e_2 e 2 in m b mb mb preserves the three axioms, but creates the SC-cycle e 1 → p o e 2 → m o e 1 e_1 \xrightarrow{po} e_2 \xrightarrow{mo} e_1 e 1 p o e 2 m o e 1 , so P P P is not robust. We therefore let
W R A ≜ (irr-hb) ∪ (write-coherence) ∪ (weak-read-coherence) ∪ (weak-atomicity) . WRA \triangleq\text{(irr-hb)} \cup\text{(write-coherence)} \cup\text{(weak-read-coherence)} \cup\text{(weak-atomicity)}. W R A ≜ (irr-hb) ∪ (write-coherence) ∪ (weak-read-coherence) ∪ (weak-atomicity) .
Adding (write-coherence) does not change which ⟨ E , s b , r f ⟩ \langle E, sb, rf\rangle ⟨ E , s b , r f ⟩ are allowed. Indeed, given a graph that satisfies the three axioms, we obtain one that also satisfies (write-coherence) by replacing, for each location x x x , the m b mb mb -edges on x x x by the successor relation of a total order on the writes and RMWs on x x x that extends h b hb hb ; such an order exists as h b hb hb is acyclic by (irr-hb). The other three axioms still hold, as (irr-hb) and (weak-read-coherence) do not mention m o mo m o , and (weak-atomicity) holds for either order. So, (write-coherence) only rules out choices of m b mb mb that contradict h b hb hb , which otherwise yield trivial violations, such as mo-edges from a write to a po-earlier write on the same location.
LRA. LRA [65 ] strengthens WRA with the irreflexivity of
( h b ∣ l o c ∖ r f ) ; [ R ∪ R M W ] ; h b ; r f − 1 . (\mathrm{hb}|_{\mathrm{loc}} \setminus\mathrm{rf}); [\mathrm{R} \cup\mathrm{RMW}]; \mathrm{hb}; \mathrm{rf}^{-1}. ( hb ∣ loc ∖ rf ) ; [ R ∪ RMW ] ; hb ; rf − 1 .
In words, a read e r e_r e r may not read from a write e w e_w e w on x x x if some read e r ′ e'_r e r ′ on x x x , with e w h b e r ′ h b e r e_w \mathrel{\mathrm{hb}} e'_r \mathrel{\mathrm{hb}} e_r e w hb e r ′ hb e r , reads from a write other than e w e_w e w . As for WRA, we include (write-coherence), and the argument above applies verbatim, as the new axiom does not mention mo. The difference with rf cannot be expressed directly. Instead, we extend the value domain to T i d × V a l \mathrm{Tid} \times\mathrm{Val} Tid × Val , so that every value also records the thread that wrote it, and we modify the LTSs accordingly (for programs given as code, the rules of Section A.1). A write of thread t t t writes ⟨ t , v ⟩ \langle t,v\rangle ⟨ t , v ⟩ instead of v v v , and a read may observe ⟨ t ′ , v ⟩ \langle t',v\rangle ⟨ t ′ , v ⟩ for any thread t ′ t' t ′ , but only uses v v v . So, the label of a read tells us which thread it reads from. This does not affect robustness, and the number of labels only grows by a factor of ∣ T i d ∣ |\mathrm{Tid}| ∣ Tid ∣ , so the bounds of § 5 still apply.
For t ∈ T i d t \in\mathrm{Tid} t ∈ Tid and x ∈ L o c x \in\mathrm{Loc} x ∈ Loc , let R x ≠ t R_x^{\ne t} R x = t be the read and RMW labels on x x x whose read value records a thread other than t t t . The new axiom is
⋃ t ∈ T i d ⋃ x ∈ L o c [ ( W x ∪ R M W x ) ∩ L a b t ≠ t ] ; h b ; [ R x ≠ t ] ; h b ; r f − 1 (local-read-coherence) \bigcup_{t \in\mathrm{Tid}} \bigcup_{x \in\mathrm{Loc}} [(\mathrm{W}_x \cup\mathrm{RMW}_x) \cap\mathrm{Lab}_t^{\ne t}]; \mathrm{hb}; [R_x^{\ne t}]; \mathrm{hb}; \mathrm{rf}^{-1}
\qquad\text{(local-read-coherence)} t ∈ Tid ⋃ x ∈ Loc ⋃ [( W x ∪ RMW x ) ∩ Lab t = t ] ; hb ; [ R x = t ] ; hb ; rf − 1 (local-read-coherence)
and L R A ≜ W R A ∪ (local-read-coherence) \mathrm{LRA} \triangleq\mathrm{WRA} \cup\text{(local-read-coherence)} LRA ≜ WRA ∪ (local-read-coherence) . We show that a graph G G G satisfies the definition of [65 ] together with (write-coherence) iff LRA holds in the corresponding graph of the modified program, where each read observes the thread of its rf-predecessor. If G G G violates WRA, then both sides fail. So, assume that G ⊨ W R A G \models\mathrm{WRA} G ⊨ WRA . Suppose that G G G violates the axiom of [65 ] , i.e., there are e w e_w e w , e r ′ e'_r e r ′ and e r e_r e r as above, where e r ′ e'_r e r ′ reads from some e w ′ ≠ e w e'_w \ne e_w e w ′ = e w . Both e w e_w e w and e w ′ e'_w e w ′ write to x x x . If e w h b e w ′ e_w \mathrel{\mathrm{hb}} e'_w e w hb e w ′ , then e w h b ∣ l o c e r ′ h b e r e_w \mathrel{\mathrm{hb}|_{\mathrm{loc}}} e'_r \mathrel{\mathrm{hb}} e_r e w hb ∣ loc e r ′ hb e r , as e w ′ r f e r ′ h b e r e'_w \mathrel{\mathrm{rf}} e'_r \mathrel{\mathrm{hb}} e_r e w ′ rf e r ′ hb e r , and this violates (weak-read-coherence), since e r e_r e r reads from e w e_w e w . Similarly, if e w ′ h b e w e'_w \mathrel{\mathrm{hb}} e_w e w ′ hb e w , then e w ′ h b ∣ l o c e w h b e r ′ e'_w \mathrel{\mathrm{hb}|_{\mathrm{loc}}} e_w \mathrel{\mathrm{hb}} e'_r e w ′ hb ∣ loc e w hb e r ′ , which violates (weak-read-coherence), since e r ′ e'_r e r ′ reads from e w ′ e'_w e w ′ . So, e w e_w e w and e w ′ e'_w e w ′ are hb-incomparable, and hence they belong to different threads, as p o ⊆ h b \mathrm{po} \subseteq\mathrm{hb} po ⊆ hb . So, in the corresponding graph, the label of e r ′ e'_r e r ′ is in R x ≠ t R_x^{\ne t} R x = t for the thread t t t of e w e_w e w , and (local-read-coherence) has a cycle through e w e_w e w . Conversely, a cycle of (local-read-coherence) yields e w e_w e w , e r ′ e'_r e r ′ and e r e_r e r as above, where e r ′ e'_r e r ′ reads from a thread other than the one of e w e_w e w , and so from a write other than e w e_w e w .
RC20. RC20 [50 ] has the access modes A n n = { r l x , r e l , a c q , a c q - r e l } \mathrm{Ann} = \{\mathrm{rlx}, \mathrm{rel}, \mathrm{acq}, \mathrm{acq\text{-}rel}\} Ann = { rlx , rel , acq , acq - rel } . Reads are rlx or acq, writes are rlx or rel, and RMWs and fences have any mode, except that fences are not rlx. The derived relations are
s w ≜ [ L a b r e l ] ; ( ( [ F ] ; p o ) ? ; r f + ; ( p o ; [ F ] ) ? ; [ L a b a c q ] and h b R C 20 ≜ ( p o ∪ s w ) + . \mathrm{sw} \triangleq[\mathrm{Lab}_{\mathrm{rel}}]; (([\mathrm{F}];\mathrm{po})?; \mathrm{rf}^{+};(\mathrm{po};[\mathrm{F}])?;[\mathrm{Lab}_{\mathrm{acq}}]
\qquad\text{and}\qquad
\mathrm{hb}_{\mathrm{RC20}} \triangleq(\mathrm{po} \cup\mathrm{sw})^{+}. sw ≜ [ Lab rel ] ; (([ F ] ; po )? ; rf + ; ( po ; [ F ])? ; [ Lab acq ] and hb RC20 ≜ ( po ∪ sw ) + .
The axioms are
m o ; r f ? ; h b R C 20 ? (rc-write-coherence) \mathrm{mo};\mathrm{rf}^{?};\mathrm{hb}_{\mathrm{RC20}}^{?}
\qquad\text{(rc-write-coherence)} mo ; rf ? ; hb RC20 ? (rc-write-coherence)
f r ; r f ? ; h b R C 20 (rc-read-coherence) \mathrm{fr};\mathrm{rf}^{?};\mathrm{hb}_{\mathrm{RC20}}
\qquad\text{(rc-read-coherence)} fr ; rf ? ; hb RC20 (rc-read-coherence)
So, RC20 ≜ \triangleq ≜ (irr-hb) ∪ \cup ∪ (atomicity) ∪ \cup ∪ (rc-write-coherence) ∪ \cup ∪ (rc-read-coherence). It forbids the violations of (atomicity) directly, and the cycles of mo; rf by (rc-write-coherence), and neither axiom involves fr. Its release/acquire fragment, with only acq reads, rel writes and acq-rel RMWs, and no fences, is RA [50 ] .
RC11. We consider the fragment of RC11 [45 ] without non-atomic accesses, as their races make the whole program undefined, which is not a constraint on single graphs. We also omit the initialization events of [45 ] , which precede all other events in po, as our graphs have none. The modes are Ann = { r l x , a c q , r e l , a c q - r e l , s c } = \{\mathrm{rlx},\mathrm{acq},\mathrm{rel},\mathrm{acq\text{-}rel},\mathrm{sc}\} = { rlx , acq , rel , acq - rel , sc } , where reads are rlx, acq or sc, writes are rlx, rel or sc, and fences are not rlx. Lahav et al. [45 ] represent an RMW by a read and a write related by rmw, with five allowed pairs of modes, which correspond to our five modes. With a single event, rf;rmw becomes rf; [RMW], and their atomicity axiom becomes (atomicity). Moreover, the rmw-edge from the read to the write of an RMW is in h b R C 11 \mathrm{hb}_{\mathrm{RC11}} hb RC11 , and it disappears, so (coherence) also requires eco to be irreflexive. The derived relations are
p o ≠ l o c ≜ ⋃ x ≠ y ( [ L a b x ] ; p o ; [ L a b y ] ) ∪ ( [ F ] ; p o ) ∪ ( p o ; [ F ] ) \mathrm{po}_{\ne\mathrm{loc}} \mathrel{\triangleq} \bigcup_{x\ne y} ([\mathrm{Lab}_x];\mathrm{po};[\mathrm{Lab}_y]) \cup([F];\mathrm{po}) \cup(\mathrm{po};[F]) po = loc ≜ x = y ⋃ ([ Lab x ] ; po ; [ Lab y ]) ∪ ([ F ] ; po ) ∪ ( po ; [ F ])
r s ≜ [ W ∪ R M W ] ; p o l o c ? ; [ W ∪ R M W ] ; ( r f ; [ R M W ] ) ∗ \mathrm{rs} \mathrel{\triangleq} [W\cup RMW];\mathrm{po}_{\mathrm{loc}}?;[W\cup RMW];(\mathrm{rf};[RMW])^{*} rs ≜ [ W ∪ R M W ] ; po loc ? ; [ W ∪ R M W ] ; ( rf ; [ R M W ] ) ∗
s w ≜ [ L a b ⪰ r e l ] ; ( [ F ] ; p o ) ? ; r s ; r f ; ( p o ; [ F ] ) ? ; [ L a b ⪰ a c q ] \mathrm{sw} \mathrel{\triangleq} [\mathrm{Lab}_{\succeq\mathrm{rel}}];([F];\mathrm{po})?;\mathrm{rs};\mathrm{rf};(\mathrm{po};[F])?;[\mathrm{Lab}_{\succeq\mathrm{acq}}] sw ≜ [ Lab ⪰ rel ] ; ([ F ] ; po )? ; rs ; rf ; ( po ; [ F ])? ; [ Lab ⪰ acq ]
h b R C 11 ≜ ( p o ∪ s w ) + \mathrm{hb}_{\mathrm{RC11}} \mathrel{\triangleq} (\mathrm{po}\cup\mathrm{sw})^{+} hb RC11 ≜ ( po ∪ sw ) +
e c o ≜ ( r f ∪ m o ∪ f r ) + \mathrm{eco} \mathrel{\triangleq} (\mathrm{rf}\cup\mathrm{mo}\cup\mathrm{fr})^{+} eco ≜ ( rf ∪ mo ∪ fr ) +
s c b ≜ p o ∪ ( p o ≠ l o c ; h b R C 11 ; p o ≠ l o c ) ∪ h b R C 11 ∣ l o c ∪ m o ∪ f r \mathrm{scb} \mathrel{\triangleq} \mathrm{po}\cup(\mathrm{po}_{\ne\mathrm{loc}};\mathrm{hb}_{\mathrm{RC11}};\mathrm{po}_{\ne\mathrm{loc}})\cup\mathrm{hb}_{\mathrm{RC11}}|_{\mathrm{loc}}\cup\mathrm{mo}\cup\mathrm{fr} scb ≜ po ∪ ( po = loc ; hb RC11 ; po = loc ) ∪ hb RC11 ∣ loc ∪ mo ∪ fr
p s c ≜ ( [ L a b s c ] ∪ ( [ L a b s c ∩ F ] ; h b R C 11 ? ) ) ; s c b ; ( [ L a b s c ] ∪ ( h b R C 11 ? ; [ L a b s c ∩ F ] ) ) \mathrm{psc} \mathrel{\triangleq} ([\mathrm{Lab}_{\mathrm{sc}}]\cup([\mathrm{Lab}_{\mathrm{sc}}\cap F];\mathrm{hb}_{\mathrm{RC11}}?));\mathrm{scb};([\mathrm{Lab}_{\mathrm{sc}}]\cup(\mathrm{hb}_{\mathrm{RC11}}?;[\mathrm{Lab}_{\mathrm{sc}}\cap F])) psc ≜ ([ Lab sc ] ∪ ([ Lab sc ∩ F ] ; hb RC11 ?)) ; scb ; ([ Lab sc ] ∪ ( hb RC11 ? ; [ Lab sc ∩ F ]))
∪ ( [ L a b s c ∩ F ] ; ( h b R C 11 ∪ ( h b R C 11 ; e c o ; h b R C 11 ) ) ; [ L a b s c ∩ F ] ) \cup\;([\mathrm{Lab}_{\mathrm{sc}}\cap F];(\mathrm{hb}_{\mathrm{RC11}}\cup(\mathrm{hb}_{\mathrm{RC11}};\mathrm{eco};\mathrm{hb}_{\mathrm{RC11}}));[\mathrm{Lab}_{\mathrm{sc}}\cap F]) ∪ ([ Lab sc ∩ F ] ; ( hb RC11 ∪ ( hb RC11 ; eco ; hb RC11 )) ; [ Lab sc ∩ F ])
where p o ≠ l o c \mathrm{po}_{\ne\mathrm{loc}} po = loc equals p o ∖ p o l o c \mathrm{po}\setminus\mathrm{po}_{\mathrm{loc}} po ∖ po loc of [45 ] , since a fence has no location. The axioms are
( h b R C 11 ; e c o ? ) ∪ e c o (\mathrm{hb}_{\mathrm{RC11}};\mathrm{eco}?)\cup\mathrm{eco} ( hb RC11 ; eco ?) ∪ eco
(coherence)
(sc)
( p o ∪ r f ) + (\mathrm{po}\cup\mathrm{rf})^{+} ( po ∪ rf ) +
(no-thin-air)
So, R C 11 ≜ \mathrm{RC11}\mathrel{\triangleq} RC11 ≜ (coherence) ∪ \cup ∪ (atomicity) ∪ \cup ∪ (sc) ∪ \cup ∪ (no-thin-air), which is prefix-closed by Lemma B.1 . It forbids the violations of (atomicity) directly, and the cycles of m o ; r f \mathrm{mo};\mathrm{rf} mo ; rf by (coherence), as m o ; r f ⊆ e c o \mathrm{mo};\mathrm{rf}\subseteq\mathrm{eco} mo ; rf ⊆ eco with either fr or f r K A T \mathrm{fr}_{\mathrm{KAT}} fr KAT .
WRC11. WRC11 [36 ] weakens RC11 by not recording a modification order: every use of mo is replaced by a relation derived from h b R C 11 \mathrm{hb}_{\mathrm{RC11}} hb RC11 and rf. We make the same adaptations as for RC11, and take rs, sw and h b R C 11 \mathrm{hb}_{\mathrm{RC11}} hb RC11 as there. The derived relations are
m o w ≜ ⋃ x ∈ L o c [ W x ∪ R M W x ] ; ( h b R C 11 ∪ ( [ L a b x ] ; r f ) ) + ; [ W x ∪ R M W x ] \mathrm{mo}_{w}\mathrel{\triangleq}\bigcup_{x\in\mathrm{Loc}}[W_x\cup RMW_x];(\mathrm{hb}_{\mathrm{RC11}}\cup([\mathrm{Lab}_x];\mathrm{rf}))^{+};[W_x\cup RMW_x] mo w ≜ x ∈ Loc ⋃ [ W x ∪ R M W x ] ; ( hb RC11 ∪ ([ Lab x ] ; rf ) ) + ; [ W x ∪ R M W x ]
f r w ≜ [ R ] ; r f − 1 ; m o w ∪ ⋃ t ∈ T i d [ R M W ∩ L a b t ] ; r f − 1 ; m o w ; [ L a b ∖ L a b t ] \mathrm{fr}_{w}\mathrel{\triangleq}[R];\mathrm{rf}^{-1};\mathrm{mo}_{w}\cup\bigcup_{t\in\mathrm{Tid}}[RMW\cap\mathrm{Lab}^{t}];\mathrm{rf}^{-1};\mathrm{mo}_{w};[\mathrm{Lab}\setminus\mathrm{Lab}^{t}] fr w ≜ [ R ] ; rf − 1 ; mo w ∪ t ∈ Tid ⋃ [ R M W ∩ Lab t ] ; rf − 1 ; mo w ; [ Lab ∖ Lab t ]
e c o w ≜ ( r f ∪ m o w ∪ f r w ) + \mathrm{eco}_{w}\mathrel{\triangleq}(\mathrm{rf}\cup\mathrm{mo}_{w}\cup\mathrm{fr}_{w})^{+} eco w ≜ ( rf ∪ mo w ∪ fr w ) +
and s c b w \mathrm{scb}_{w} scb w and p s c w \mathrm{psc}_{w} psc w are scb and psc with mo, fr and eco replaced by m o w \mathrm{mo}_{w} mo w , f r w \mathrm{fr}_{w} fr w and e c o w \mathrm{eco}_{w} eco w . Note that m o w \mathrm{mo}_{w} mo w only follows rf-edges on x x x , as in [36 ] , and is thus in general smaller than the restriction of ( p o ∪ r f ) + (\mathrm{po}\cup\mathrm{rf})^{+} ( po ∪ rf ) + to the writes and RMWs on x x x . The from-read relation of [36 ] is ( r f − 1 ; m o w ) ∖ i d (\mathrm{rf}^{-1};\mathrm{mo}_{w})\setminus\mathrm{id} ( rf − 1 ; mo w ) ∖ id . For an RMW e e e of thread t t t , f r w \mathrm{fr}_{w} fr w omits its edges to all events of t t t , and not only to e e e itself, which KAT cannot single out. The omitted edges do not matter. An edge from e e e to a po-later event is also an m o w \mathrm{mo}_{w} mo w -edge, and both relations occur in the same places in the axioms below. An edge from e e e to a po-earlier event e ′ e' e ′ yields e → m o w e ′ → m o w e e\mathrel{\xrightarrow{\mathrm{mo}_{w}}}e'\mathrel{\xrightarrow{\mathrm{mo}_{w}}}e e mo w e ′ mo w e for the event e w e_{w} e w that e e e reads from, which (w-atomicity) forbids. The axioms are
( h b R C 11 ; e c o w ? ) ∪ e c o w (\mathrm{hb}_{\mathrm{RC11}};\mathrm{eco}_{w}?)\cup\mathrm{eco}_{w} ( hb RC11 ; eco w ?) ∪ eco w
(w-coherence)
m o w ; m o w ; r f − 1 \mathrm{mo}_{w};\mathrm{mo}_{w};\mathrm{rf}^{-1} mo w ; mo w ; rf − 1
(w-atomicity)
p s c w + \mathrm{psc}_{w}^{+} psc w +
(w-sc)
m o ; m o w \mathrm{mo};\mathrm{mo}_{w} mo ; mo w
(mo-agreement)
So,
W R C 11 ≜ ( w-coherence ) ∪ ( w-atomicity ) ∪ ( w-sc ) \mathrm{WRC11}\mathrel{\triangleq}(\text{w-coherence})\cup(\text{w-atomicity})\cup(\text{w-sc}) WRC11 ≜ ( w-coherence ) ∪ ( w-atomicity ) ∪ ( w-sc )
∪ ( no-thin-air ) ∪ ( weak-atomicity ) ∪ ( mo-agreement ) , \cup\;(\text{no-thin-air})\cup(\text{weak-atomicity})\cup(\text{mo-agreement}), ∪ ( no-thin-air ) ∪ ( weak-atomicity ) ∪ ( mo-agreement ) ,
which is prefix-closed by Lemma B.1 . As for WRA, the axioms of [36 ] do not constrain mo \operatorname{mo} mo , and we add (mo-agreement) so that mo \operatorname{mo} mo extends mo W \operatorname{mo}_{W} mo W . This does not change which ⟨ E , sb , rf ⟩ \langle E,\operatorname{sb},\operatorname{rf}\rangle ⟨ E , sb , rf ⟩ are allowed. Indeed, hb R C 11 ⊆ ( po ∪ rf ) + \operatorname{hb}_{\mathrm{RC11}} \subseteq(\operatorname{po} \cup\operatorname{rf})^{+} hb RC11 ⊆ ( po ∪ rf ) + , so mo W \operatorname{mo}_{W} mo W is acyclic by (no-thin-air), and we can replace, for each location x x x , the mb \operatorname{mb} mb -edges on x x x by the successor relation of a total order on the writes and RMWs on x x x that extends mo W \operatorname{mo}_{W} mo W . The other axioms still hold, as only (weak-atomicity) mentions mo \operatorname{mo} mo , and it holds for either order.
OCaml. We take the OCaml memory model of [32 ] , which has no RMWs. We fix a set L o c a t ⊆ L o c \mathrm{Loc}_{\mathrm{at}} \subseteq\mathrm{Loc} Loc at ⊆ Loc of atomic locations, and we let L a b a t \mathrm{Lab}_{\mathrm{at}} Lab at be the labels on atomic locations. The derived relation is
hb O C a m l ≜ ( po ∪ ( [ L a b a t ] ; ( mo ∪ rf ) ) + ) , \operatorname{hb}_{\mathrm{OCaml}} \triangleq\left(\operatorname{po} \cup\left([\mathrm{Lab}_{\mathrm{at}}];(\operatorname{mo} \cup\operatorname{rf})\right)^{+}\right), hb OCaml ≜ ( po ∪ ( [ Lab at ] ; ( mo ∪ rf ) ) + ) ,
where we omit the initial writes of [32 ] , as our graphs have none. The axioms are
( hb O C a m l ∪ rf ∪ ( [ L a b a t ] ; fr ) ) + (causality) \left(\operatorname{hb}_{\mathrm{OCaml}} \cup\operatorname{rf} \cup\left([\mathrm{Lab}_{\mathrm{at}}];\operatorname{fr}\right)\right)^{+}
\qquad\text{(causality)} ( hb OCaml ∪ rf ∪ ( [ Lab at ] ; fr ) ) + (causality)
hb O C a m l ; mo (CoWW) \operatorname{hb}_{\mathrm{OCaml}};\operatorname{mo}
\qquad\text{(CoWW)} hb OCaml ; mo (CoWW)
hb O C a m l ; fr (CoWR) \operatorname{hb}_{\mathrm{OCaml}};\operatorname{fr}
\qquad\text{(CoWR)} hb OCaml ; fr (CoWR)
So, O C a m l ≜ \mathrm{OCaml} \triangleq OCaml ≜ (causality) ∪ \cup ∪ (CoWW) ∪ \cup ∪ (CoWR). (causality) contains ( po ∪ rf ) + (\operatorname{po} \cup\operatorname{rf})^{+} ( po ∪ rf ) + , and so OCaml is prefix-closed by Lemma B.1 .
PSI. We consider Parallel Snapshot Isolation [58 ] with unary transactions, where every event is its own transaction. Then, lifting a relation to transactions leaves it unchanged, and by [58 Lemma 1] , PSI has the derived relation hb P S I ≜ ( po ∪ rf ∪ mo ) + \operatorname{hb}_{\mathrm{PSI}} \triangleq(\operatorname{po} \cup\operatorname{rf} \cup\operatorname{mo})^{+} hb PSI ≜ ( po ∪ rf ∪ mo ) + and the single axiom
( hb P S I ∣ l o c ∪ mo ∪ fr ) + (psi) \left(\operatorname{hb}_{\mathrm{PSI}}|_{\mathrm{loc}} \cup\operatorname{mo} \cup\operatorname{fr}\right)^{+}
\qquad\text{(psi)} ( hb PSI ∣ loc ∪ mo ∪ fr ) + (psi)
So, P S I ≜ \mathrm{PSI} \triangleq PSI ≜ (psi). As rf ⊆ hb P S I ∣ l o c \operatorname{rf} \subseteq\operatorname{hb}_{\mathrm{PSI}}|_{\mathrm{loc}} rf ⊆ hb PSI ∣ loc , (psi) forbids the cycles of rf ∪ mo ∪ fr \operatorname{rf} \cup\operatorname{mo} \cup\operatorname{fr} rf ∪ mo ∪ fr , and hence, as for SC, the violations of (atomicity) and the cycles of mo ; rf \operatorname{mo};\operatorname{rf} mo ; rf , with either fr \operatorname{fr} fr or fr K A T \operatorname{fr}_{\mathrm{KAT}} fr KAT . Every ( po ∪ rf ) (\operatorname{po} \cup\operatorname{rf}) ( po ∪ rf ) -cycle contains an rf \operatorname{rf} rf -edge, and hence an event e e e with a location, for which ⟨ e , e ⟩ ∈ hb P S I ∣ l o c \langle e,e\rangle\in\operatorname{hb}_{\mathrm{PSI}}|_{\mathrm{loc}} ⟨ e , e ⟩ ∈ hb PSI ∣ loc . So, PSI forbids ( po ∪ rf ) (\operatorname{po} \cup\operatorname{rf}) ( po ∪ rf ) -cycles, and it is prefix-closed by Lemma B.1 .
Proofs of SEC:PW
Lemma 3.2. For every execution graph G G G , if G ⊨ S C G \models\mathrm{SC} G ⊨ SC then pw ( G ) ≤ ∣ T i d ∣ + ∣ L o c ∣ \operatorname{pw}(G) \leq|\mathrm{Tid}| + |\mathrm{Loc}| pw ( G ) ≤ ∣ Tid ∣ + ∣ Loc ∣ .
Proof. This proof uses the same construction as [22 ] . By definition of SC (§ 2.4 ), G ⊨ S C G \models\mathrm{SC} G ⊨ SC iff po ∪ rf ∪ mo ∪ fr \operatorname{po} \cup\operatorname{rf} \cup\operatorname{mo} \cup\operatorname{fr} po ∪ rf ∪ mo ∪ fr is acyclic in G G G . So, we can fix a linear extension σ = e 1 , e 2 , … , e n \sigma= e_1,e_2,\ldots,e_n σ = e 1 , e 2 , … , e n of it. We write e ≺ e ′ e \prec e' e ≺ e ′ when e e e precedes e ′ e' e ′ in σ \sigma σ .
For i ∈ [ n ] i \in[n] i ∈ [ n ] , the bag X i X_i X i contains e i e_i e i , together with, for each thread t ∈ T i d t \in\mathrm{Tid} t ∈ Tid , the last event of t t t before e i e_i e i in σ \sigma σ , and, for each location x ∈ L o c x \in\mathrm{Loc} x ∈ Loc , the last write or RMW on x x x before e i e_i e i in σ \sigma σ , whenever these exist. So, ∣ X i ∣ ≤ 1 + ∣ T i d ∣ + ∣ L o c ∣ |X_i| \leq1 + |\mathrm{Tid}| + |\mathrm{Loc}| ∣ X i ∣ ≤ 1 + ∣ Tid ∣ + ∣ Loc ∣ , and the width is at most ∣ T i d ∣ + ∣ L o c ∣ |\mathrm{Tid}| + |\mathrm{Loc}| ∣ Tid ∣ + ∣ Loc ∣ . It remains to show that X 1 , X 2 , … , X n X_1,X_2,\ldots,X_n X 1 , X 2 , … , X n is a path decomposition of G G G , i.e., that every event lies in a contiguous range of bags, and that the endpoints of every edge share a bag.
First, we show that every event lies in a contiguous range of bags. Consider an event e i e_i e i . It first appears in X i X_i X i . It then stays in the bags as the last event of its thread, up to the bag of the next event of its thread. If e i e_i e i is a write or RMW, it also stays as the last write or RMW on its location, up to the bag of the next write or RMW on that location, or up to X n X_n X n if there is none. Both ranges start at X i X_i X i , so their union is contiguous.
Next, we show that the endpoints of every edge share a bag. Let e → sb e ′ e \mathrel{\xrightarrow{\operatorname{sb}}} e' e sb e ′ , with e ′ = e i ′ e' = e_{i'} e ′ = e i ′ . Then e e e is the event of its thread that comes right before e ′ e' e ′ in po \operatorname{po} po . Since σ \sigma σ extends po \operatorname{po} po , e e e is also the last event of its thread before e ′ e' e ′ in σ \sigma σ . So, e ∈ X i ′ e \in X_i' e ∈ X i ′ , and both endpoints lie in X i ′ X_i' X i ′ . The case of mb-edges is the same, with mo in place of po, and the writes and RMWs on a location in place of the events of a thread. Finally, for rf-edges, let e → r f e ′ e \mathrel{\xrightarrow{\mathrm{rf}}} e' e rf e ′ , with e ′ = e i ′ e'=e_i' e ′ = e i ′ and x ≜ loc ( e ) x \triangleq\operatorname{loc}(e) x ≜ loc ( e ) . We show that e e e is the last write or RMW on x x x before e ′ e' e ′ in σ \sigma σ , so that both endpoints lie in X i ′ X_i' X i ′ . Suppose, towards a contradiction, that some write or RMW e ′ ′ e'' e ′′ on x x x lies in between, i.e., e ≺ e ′ ′ ≺ e ′ e \prec e'' \prec e' e ≺ e ′′ ≺ e ′ . Since mo totally orders the writes and RMWs on x x x , and σ \sigma σ extends mo, we have e → m o e ′ ′ e \mathrel{\xrightarrow{\mathrm{mo}}} e'' e mo e ′′ . If e ′ e' e ′ is a read, then e ′ → f r e ′ ′ e' \mathrel{\xrightarrow{\mathrm{fr}}} e'' e ′ fr e ′′ , and since σ \sigma σ extends fr, we get e ′ ≺ e ′ ′ e' \prec e'' e ′ ≺ e ′′ . This contradicts e ′ ′ ≺ e ′ e'' \prec e' e ′′ ≺ e ′ . Otherwise, e ′ e' e ′ is an RMW on x x x , and for the same reason we have e ′ ′ → m o e ′ e'' \mathrel{\xrightarrow{\mathrm{mo}}} e' e ′′ mo e ′ . So, e → m o e ′ ′ → m o e ′ e \mathrel{\xrightarrow{\mathrm{mo}}} e'' \mathrel{\xrightarrow{\mathrm{mo}}} e' e mo e ′′ mo e ′ , and hence e ′ → f r e ′ e' \mathrel{\xrightarrow{\mathrm{fr}}} e' e ′ fr e ′ . This is a cyclic realization of fr, which contradicts G ⊨ S C G \models\mathrm{SC} G ⊨ SC .
Lemma 3.3. Every prefix-closed memory model admits ( p w S C + 1 ) (\mathrm{pw}_{\mathrm{SC}}+1) ( pw SC + 1 ) -pw-bounded witnesses.
Proof. Fix a prefix-closed memory model MM, and a program P that is not robust against MM. Let G G G be a witness for the non-MM-robustness of P with the fewest events. We show that pw ( G ) ≤ p w S C + 1 \operatorname{pw}(G) \le\mathrm{pw}_{\mathrm{SC}}+1 pw ( G ) ≤ pw SC + 1 .
Since G G G is a witness, G ⊭ S C G \not\models\mathrm{SC} G ⊨ SC , so G G G is non-empty. By prefix-closedness, some maximal event e e e of G G G satisfies G ∖ { e } ∈ ⟦ P ⟧ M M G \setminus\{e\} \in\llbracket P \rrbracket_{\mathrm{MM}} G ∖ { e } ∈ [ [ P ] ] MM . Since G ∖ { e } G \setminus\{e\} G ∖ { e } has fewer events than G G G , it is not a witness. So, G ∖ { e } ⊨ S C G \setminus\{e\} \models\mathrm{SC} G ∖ { e } ⊨ SC , and pw ( G ∖ { e } ) ≤ p w S C \operatorname{pw}(G \setminus\{e\}) \le\mathrm{pw}_{\mathrm{SC}} pw ( G ∖ { e }) ≤ pw SC by Lemma 3.2. It remains to add e e e back. Let H H H be the graph obtained from G G G by restricting its events and its three relations to G . E ∖ { e } G.E \setminus\{e\} G . E ∖ { e } . Note that H H H and G ∖ { e } G \setminus\{e\} G ∖ { e } agree on sb and rf. On mb, the graph G ∖ { e } G \setminus\{e\} G ∖ { e } may additionally contain the edge that bridges over e e e , due to the transitive reduction. So, every edge of H H H is an edge of G ∖ { e } G \setminus\{e\} G ∖ { e } , every path decomposition of G ∖ { e } G \setminus\{e\} G ∖ { e } is one of H H H , and pw ( H ) ≤ p w S C \operatorname{pw}(H) \le\mathrm{pw}_{\mathrm{SC}} pw ( H ) ≤ pw SC . Finally, adding e e e to every bag of a path decomposition of H H H gives a path decomposition of G G G . Hence, pw ( G ) ≤ pw ( H ) + 1 ≤ p w S C + 1 \operatorname{pw}(G) \le\operatorname{pw}(H)+1 \le\mathrm{pw}_{\mathrm{SC}}+1 pw ( G ) ≤ pw ( H ) + 1 ≤ pw SC + 1 .
Proofs of SEC:ALGEBRA
Lemma 4.1. For any closed w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^* w ∈ Ops ( k + 1 ) ∗ , the sequence X w 0 , X w 1 , … , X w ∣ w ∣ X^{w_0}, X^{w_1}, \ldots, X^{w_{|w|}} X w 0 , X w 1 , … , X w ∣ w ∣ , where X w i ≜ dom ( χ w i ) X^{w_i} \triangleq\operatorname{dom}(\chi^{w_i}) X w i ≜ dom ( χ w i ) , is a very nice path decomposition of G w G^w G w of width at most k k k , in which each bag X w i X^{w_i} X w i with i ≥ 1 i \ge1 i ≥ 1 is labeled by the step corresponding to the i i i -th operation of w w w . Conversely, for any free execution graph G G G and very nice path decomposition X 1 , X 2 , … , X n X_1, X_2, \ldots, X_n X 1 , X 2 , … , X n of G G G of width at most k k k , there is a closed w ∈ Ops ( k + 1 ) ∗ w \in\operatorname{Ops}(k+1)^* w ∈ Ops ( k + 1 ) ∗ of length n − 1 n-1 n − 1 such that G w = G G^w=G G w = G and X w i = X i + 1 X^{w_i}=X_{i+1} X w i = X i + 1 for every i ∈ { 0 , … , n − 1 } i \in\{0,\ldots,n-1\} i ∈ { 0 , … , n − 1 } .
Proof. For the first part, let w w w be closed, and consider the bags X w i = dom ( χ w i ) X^{w_i}=\operatorname{dom}(\chi^{w_i}) X w i = dom ( χ w i ) . Each bag holds at most k + 1 k+1 k + 1 events, as χ w i \chi^{w_i} χ w i is injective, and X w 0 = X w ∣ w ∣ = ∅ X^{w_0}=X^{w_{|w|}}=\varnothing X w 0 = X w ∣ w ∣ = ∅ , as w 0 = ε w_0=\varepsilon w 0 = ε and w w w is closed. We label X w i X^{w_i} X w i by the step corresponding to the i i i -th operation of w w w . An operation Intro l a b ( c ) \operatorname{Intro}_{\mathrm{lab}(c)} Intro lab ( c ) adds a new event e e e to the bag, which is the step Introduce e e e . An operation Forget ( c ) \operatorname{Forget}(c) Forget ( c ) removes χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) from the bag, which is the step Forget χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) . An operation Intro b ( c 1 , c 2 ) \operatorname{Intro}_b(c_1,c_2) Intro b ( c 1 , c 2 ) leaves the bag unchanged and adds a new edge χ − 1 ( c 1 ) → b χ − 1 ( c 2 ) \chi^{-1}(c_1) \mathrel{\xrightarrow{b}} \chi^{-1}(c_2) χ − 1 ( c 1 ) b χ − 1 ( c 2 ) whose endpoints are both in the bag, which is the step Introduce of that edge. Every event and every edge of G w G^w G w is added by exactly one operation, so each of them is introduced exactly once. Finally, an event stays in the bags from its Intro until its color is forgotten, after which nothing colors it again, so it occupies a contiguous range of bags.
For the converse, let X 1 , … , X n X_1,\ldots,X_n X 1 , … , X n be a very nice path decomposition of G G G of width at most k k k . We translate its steps in order, keeping an injective map χ \chi χ from the current bag to [ k + 1 ] [k+1] [ k + 1 ] . Introducing e e e becomes Intro ( lab ( e ) , c ) \operatorname{Intro}(\operatorname{lab}(e),c) Intro ( lab ( e ) , c ) for some inactive c c c , which exists because the bag before the step has at most k k k events. Forgetting e e e becomes Forget ( χ ( e ) ) \operatorname{Forget}(\chi(e)) Forget ( χ ( e )) . Introducing an edge e 1 → b e 2 e_1 \mathrel{\xrightarrow{b}} e_2 e 1 b e 2 becomes Intro b ( χ ( e 1 ) , χ ( e 2 ) ) \operatorname{Intro}_b(\chi(e_1),\chi(e_2)) Intro b ( χ ( e 1 ) , χ ( e 2 )) . The preconditions hold by construction, where each drawn edge is new as every edge of G G G is introduced exactly once, and X w i = X i + 1 X^{w_i}=X_{i+1} X w i = X i + 1 for every i i i . As every event and every
edge of G G G is introduced exactly once, G w = G G^w = G G w = G , up to the renaming of identifiers of § 4.1 . Finally, w w w is closed, as X n X_n X n is empty. □
Proofs of SEC:AUT
This section follows the structure of § 5 . For each automaton, we first describe the state it reaches after reading a prefix of the word, in the form of an invariant. We then derive the correctness of the automaton from this invariant.
Proofs of SUBSEC:AUTWF
In this subsection, we prove Lemma 5.1, i.e., that A W F k \mathcal{A}^{k}_{\mathrm{WF}} A WF k recognizes the words that induce execution graphs. We treat its four components in turn, and then their product.
Closedness of the word. We start with A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k , whose states ⟨ Q a c t , Q e d g ⟩ \langle Q_{\mathrm{act}}, Q_{\mathrm{edg}}\rangle ⟨ Q act , Q edg ⟩ record the active colors and the edges drawn between their events. Its initial and unique accepting state is ⟨ ∅ , ∅ ⟩ \langle\varnothing, \varnothing\rangle ⟨ ∅ , ∅ ⟩ , and its rules are the following.
op = Intro ( lab , c ) c ∉ Q a c t ⟨ Q a c t , Q e d g ⟩ → op ⟨ Q a c t ∪ { c } , Q e d g ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\qquad c\notin Q_{\mathrm{act}}\\
&\langle Q_{\mathrm{act}},Q_{\mathrm{edg}}\rangle\xrightarrow{\operatorname{op}} \langle Q_{\mathrm{act}}\cup\{c\},Q_{\mathrm{edg}}\rangle
\end{aligned} op = Intro ( lab , c ) c ∈ / Q act ⟨ Q act , Q edg ⟩ op ⟨ Q act ∪ { c } , Q edg ⟩
op = Forget ( c ) c ∈ Q a c t Q e d g ′ = { ⟨ b , c 1 , c 2 ⟩ ∈ Q e d g ∣ c ∉ { c 1 , c 2 } } ⟨ Q a c t , Q e d g ⟩ → op ⟨ Q a c t ∖ { c } , Q e d g ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Forget}(c)\qquad c\in Q_{\mathrm{act}}\\
&Q'_{\mathrm{edg}}=\{\langle b,c_1,c_2\rangle\in Q_{\mathrm{edg}}\mid c\notin\{c_1,c_2\}\}\\
&\langle Q_{\mathrm{act}},Q_{\mathrm{edg}}\rangle\xrightarrow{\operatorname{op}} \langle Q_{\mathrm{act}}\setminus\{c\},Q'_{\mathrm{edg}}\rangle
\end{aligned} op = Forget ( c ) c ∈ Q act Q edg ′ = {⟨ b , c 1 , c 2 ⟩ ∈ Q edg ∣ c ∈ / { c 1 , c 2 }} ⟨ Q act , Q edg ⟩ op ⟨ Q act ∖ { c } , Q edg ′ ⟩
op = Intro b ( c 1 , c 2 ) c 1 , c 2 ∈ Q a c t ⟨ b , c 1 , c 2 ⟩ ∉ Q e d g ⟨ Q a c t , Q e d g ⟩ → op ⟨ Q a c t , Q e d g ∪ { ⟨ b , c 1 , c 2 ⟩ } ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}_{b}(c_1,c_2)\qquad c_1,c_2\in Q_{\mathrm{act}}\qquad\langle b,c_1,c_2\rangle\notin Q_{\mathrm{edg}}\\
&\langle Q_{\mathrm{act}},Q_{\mathrm{edg}}\rangle\xrightarrow{\operatorname{op}} \langle Q_{\mathrm{act}},Q_{\mathrm{edg}}\cup\{\langle b,c_1,c_2\rangle\}\rangle
\end{aligned} op = Intro b ( c 1 , c 2 ) c 1 , c 2 ∈ Q act ⟨ b , c 1 , c 2 ⟩ ∈ / Q edg ⟨ Q act , Q edg ⟩ op ⟨ Q act , Q edg ∪ {⟨ b , c 1 , c 2 ⟩}⟩
Lemma E.1. For every k ∈ N k\in\mathbb{N} k ∈ N , there is a deterministic word automaton A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k with 2 O ( k 2 ) 2^{O(k^2)} 2 O ( k 2 ) states that accepts w ∈ Ops ( k + 1 ) w\in\operatorname{Ops}(k+1) w ∈ Ops ( k + 1 ) iff w w w is closed.
Proof. A state is a subset Q a c t Q_{\mathrm{act}} Q act of [ k + 1 ] [k+1] [ k + 1 ] together with a subset Q e d g Q_{\mathrm{edg}} Q edg of { s b , r f , m b } × [ k + 1 ] 2 \{\mathrm{sb},\mathrm{rf},\mathrm{mb}\}\times[k+1]^2 { sb , rf , mb } × [ k + 1 ] 2 , so A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k has at most 2 k + 1 ⋅ 2 3 ( k + 1 ) 2 = 2 O ( k 2 ) 2^{k+1}\cdot2^{3(k+1)^2}=2^{O(k^2)} 2 k + 1 ⋅ 2 3 ( k + 1 ) 2 = 2 O ( k 2 ) states. At most one rule applies to each pair of a state and a letter, so it is deterministic. By induction on ∣ w ∣ |w| ∣ w ∣ , if A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k has a run on w w w , then w w w is well-formed and the state it reaches is ⟨ img ( χ w ) , Q e d g ⟩ \langle\operatorname{img}(\chi^w),Q_{\mathrm{edg}}\rangle ⟨ img ( χ w ) , Q edg ⟩ , where ⟨ b , c 1 , c 2 ⟩ ∈ Q e d g \langle b,c_1,c_2\rangle\in Q_{\mathrm{edg}} ⟨ b , c 1 , c 2 ⟩ ∈ Q edg iff ⟨ χ − 1 ( c 1 ) , χ − 1 ( c 2 ) ⟩ ∈ G w . b \langle\chi^{-1}(c_1),\chi^{-1}(c_2)\rangle\in G^w.b ⟨ χ − 1 ( c 1 ) , χ − 1 ( c 2 )⟩ ∈ G w . b . For Intro \operatorname{Intro} Intro , the new event has no edges. For Intro b \operatorname{Intro}_b Intro b , the drawn edge is added on both sides. For Forget ( c ) \operatorname{Forget}(c) Forget ( c ) , the edges that mention c c c are discarded, and the other active colors keep their events. So, each rule is the precondition of its operation in § 4.1 read on the state, and a run exists exactly when every operation of w w w meets its precondition, i.e., when w w w is well-formed. The unique accepting state is ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ , which by the same induction says dom ( χ w ) = ∅ \operatorname{dom}(\chi^w)=\varnothing dom ( χ w ) = ∅ , i.e., that w w w is closed. □
Well-formedness of s b \mathrm{sb} sb . The automaton A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k is more involved. Throughout, w w w is well-formed, G c w = ⟨ E , s b , r f , m b , χ ⟩ G^w_c=\langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb},\chi\rangle G c w = ⟨ E , sb , rf , mb , χ ⟩ , and we call an event colored when it lies in dom ( χ ) \operatorname{dom}(\chi) dom ( χ ) . The components of s b \mathrm{sb} sb are the connected components of the graph on E E E whose edges are the sb-edges taken in either direction, so that two events are connected iff they lie in the same component. We first note that the sb-edges of an uncolored event are final, as Intro s b \operatorname{Intro}_{\mathrm{sb}} Intro sb only draws edges between colored events, and a forgotten event is never colored again.
Transition rules. When an edge joins two components, their colors take the smaller of the two representatives, and when a representative is forgotten, the colors it represents take the smallest among them. Formally, merge ( c 1 , c 2 , λ r e p ) \operatorname{merge}(c_1,c_2,\lambda_{\mathrm{rep}}) merge ( c 1 , c 2 , λ rep ) maps every c c c with λ r e p ( c ) ∈ { λ r e p ( c 1 ) , λ r e p ( c 2 ) } \lambda_{\mathrm{rep}}(c)\in\{\lambda_{\mathrm{rep}}(c_1),\lambda_{\mathrm{rep}}(c_2)\} λ rep ( c ) ∈ { λ rep ( c 1 ) , λ rep ( c 2 )} to min { λ r e p ( c 1 ) , λ r e p ( c 2 ) } \min\{\lambda_{\mathrm{rep}}(c_1),\lambda_{\mathrm{rep}}(c_2)\} min { λ rep ( c 1 ) , λ rep ( c 2 )} , and every other c ∈ dom ( λ r e p ) c\in\operatorname{dom}(\lambda_{\mathrm{rep}}) c ∈ dom ( λ rep ) to λ r e p ( c ) \lambda_{\mathrm{rep}}(c) λ rep ( c ) . Similarly, drop ( c , λ r e p ) \operatorname{drop}(c,\lambda_{\mathrm{rep}}) drop ( c , λ rep ) is defined on dom ( λ r e p ) ∖ { c } \operatorname{dom}(\lambda_{\mathrm{rep}})\setminus\{c\} dom ( λ rep ) ∖ { c } , maps every c ′ c' c ′ with λ r e p ( c ′ ) = c \lambda_{\mathrm{rep}}(c')=c λ rep ( c ′ ) = c to min { c ′ ′ ∣ λ r e p ( c ′ ′ ) = c } \min\{c''\mid\lambda_{\mathrm{rep}}(c'')=c\} min { c ′′ ∣ λ rep ( c ′′ ) = c } , and every other c ′ c' c ′ to λ r e p ( c ′ ) \lambda_{rep}(c') λ r e p ( c ′ ) . The initial state is ⟨ ∅ , ∅ , ∅ , ∅ , ∅ , ∅ ⟩ \langle\varnothing,\varnothing,\varnothing,\varnothing,\varnothing,\varnothing\rangle ⟨ ∅ , ∅ , ∅ , ∅ , ∅ , ∅ ⟩ , and every state is accepting. In each rule below, the components that are not mentioned are unchanged.
op = Intro ( lab , c ) λ r e p ′ = λ r e p ∪ { c ↦ c } λ t h r ′ = λ t h r ∪ { c ↦ tid ( lab ) } \operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\qquad\lambda'_{rep}=\lambda_{rep}\cup\{c\mapsto c\}\qquad\lambda'_{thr}=\lambda_{thr}\cup\{c\mapsto\operatorname{tid}(\operatorname{lab})\} op = Intro ( lab , c ) λ r e p ′ = λ r e p ∪ { c ↦ c } λ t h r ′ = λ t h r ∪ { c ↦ tid ( lab )}
⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩ \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle\xrightarrow{\operatorname{op}} \langle Q'_{in},Q'_{out},Q'_{fst},Q'_{lst},\lambda'_{rep},\lambda'_{thr}\rangle ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ op ⟨ Q in ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩
op = Forget ( c ) t = λ t h r ( c ) c ∉ Q i n ⇒ t ∉ Q f s t c ∉ Q o u t ⇒ t ∉ Q l s t \operatorname{op}=\operatorname{Forget}(c)\qquad t=\lambda_{thr}(c)\qquad c\notin Q_{in}\Rightarrow t\notin Q_{fst}\qquad c\notin Q_{out}\Rightarrow t\notin Q_{lst} op = Forget ( c ) t = λ t h r ( c ) c ∈ / Q in ⇒ t ∈ / Q f s t c ∈ / Q o u t ⇒ t ∈ / Q l s t
Q f s t ′ = Q f s t ∪ { t ∣ c ∉ Q i n } Q l s t ′ = Q l s t ∪ { t ∣ c ∉ Q o u t } Q i n ′ = Q i n ∖ { c } Q o u t ′ = Q o u t ∖ { c } Q'_{fst}=Q_{fst}\cup\{t\mid c\notin Q_{in}\}\qquad Q'_{lst}=Q_{lst}\cup\{t\mid c\notin Q_{out}\}\qquad Q'_{in}=Q_{in}\setminus\{c\}\qquad Q'_{out}=Q_{out}\setminus\{c\} Q f s t ′ = Q f s t ∪ { t ∣ c ∈ / Q in } Q l s t ′ = Q l s t ∪ { t ∣ c ∈ / Q o u t } Q in ′ = Q in ∖ { c } Q o u t ′ = Q o u t ∖ { c }
λ r e p ′ = drop ( c , λ r e p ) λ t h r ′ = λ t h r ∖ { c ↦ t } \lambda'_{rep}=\operatorname{drop}(c,\lambda_{rep})\qquad\lambda'_{thr}=\lambda_{thr}\setminus\{c\mapsto t\} λ r e p ′ = drop ( c , λ r e p ) λ t h r ′ = λ t h r ∖ { c ↦ t }
⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩ \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle\xrightarrow{\operatorname{op}} \langle Q'_{in},Q'_{out},Q'_{fst},Q'_{lst},\lambda'_{rep},\lambda'_{thr}\rangle ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ op ⟨ Q in ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩
op = Intro s b ( c 1 , c 2 ) λ t h r ( c 1 ) = λ t h r ( c 2 ) c 1 ∉ Q o u t c 2 ∉ Q i n λ r e p ( c 1 ) ≠ λ r e p ( c 2 ) \operatorname{op}=\operatorname{Intro}_{sb}(c_1,c_2)\qquad\lambda_{thr}(c_1)=\lambda_{thr}(c_2)\qquad c_1\notin Q_{out}\qquad c_2\notin Q_{in}\qquad\lambda_{rep}(c_1)\ne\lambda_{rep}(c_2) op = Intro s b ( c 1 , c 2 ) λ t h r ( c 1 ) = λ t h r ( c 2 ) c 1 ∈ / Q o u t c 2 ∈ / Q in λ r e p ( c 1 ) = λ r e p ( c 2 )
Q o u t ′ = Q o u t ∪ { c 1 } Q i n ′ = Q i n ∪ { c 2 } λ r e p ′ = merge ( c 1 , c 2 , λ r e p ) Q'_{out}=Q_{out}\cup\{c_1\}\qquad Q'_{in}=Q_{in}\cup\{c_2\}\qquad\lambda'_{rep}=\operatorname{merge}(c_1,c_2,\lambda_{rep}) Q o u t ′ = Q o u t ∪ { c 1 } Q in ′ = Q in ∪ { c 2 } λ r e p ′ = merge ( c 1 , c 2 , λ r e p )
⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩ \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle\xrightarrow{\operatorname{op}} \langle Q'_{in},Q'_{out},Q'_{fst},Q'_{lst},\lambda'_{rep},\lambda'_{thr}\rangle ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ op ⟨ Q in ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ t h r ′ ⟩
op = Intro b ( c 1 , c 2 ) b ∈ { r f , m b } \operatorname{op}=\operatorname{Intro}_{b}(c_1,c_2)\qquad b\in\{\mathrm{rf},\mathrm{mb}\} op = Intro b ( c 1 , c 2 ) b ∈ { rf , mb }
⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ → op ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle\xrightarrow{\operatorname{op}} \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ op ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩
Invariant. The following lemma describes the state that A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k reaches after reading w w w .
Lemma E.2. Let w w w be well-formed, and suppose that A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k has a run on w w w . Then the state
⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ \langle Q_{in},Q_{out},Q_{fst},Q_{lst},\lambda_{rep},\lambda_{thr}\rangle ⟨ Q in , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ that it reaches satisfies the following.
for every active color c c c , c ∈ Q i n c\in Q_{in} c ∈ Q in iff χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) has an incoming sb-edge, and c ∈ Q o u t c\in Q_{out} c ∈ Q o u t iff it has an outgoing one, and Q i n , Q o u t ⊆ img ( χ w ) Q_{in},Q_{out}\subseteq\operatorname{img}(\chi^{w}) Q in , Q o u t ⊆ img ( χ w ) ;
t ∈ Q f s t t\in Q_{fst} t ∈ Q f s t iff t t t has an uncolored first event, and t ∈ Q l s t t\in Q_{lst} t ∈ Q l s t iff t t t has an uncolored last event;
λ r e p ( c ) \lambda_{rep}(c) λ r e p ( c ) is the smallest active color whose event lies in the component of χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) ;
dom ( λ t h r ) = dom ( λ r e p ) = img ( χ w ) \operatorname{dom}(\lambda_{thr})=\operatorname{dom}(\lambda_{rep})=\operatorname{img}(\chi^{w}) dom ( λ t h r ) = dom ( λ r e p ) = img ( χ w ) and λ t h r ( c ) = tid ( χ − 1 ( c ) ) \lambda_{thr}(c)=\operatorname{tid}(\chi^{-1}(c)) λ t h r ( c ) = tid ( χ − 1 ( c )) .
Proof. By induction on ∣ w ∣ |w| ∣ w ∣ . The empty word gives the initial state and G c ε = ⊥ G^{\varepsilon}_{c}=\bot G c ε = ⊥ , for which all four claims hold vacuously. For the inductive step, let op \operatorname{op} op be the last operation of w w w and assume the claims for the preceding prefix.
Intro ( lab , c ) \operatorname{Intro}(\operatorname{lab},c) Intro ( lab , c ) . The introduced event is colored by c c c and has no edges, so it forms a component of its own, of which c c c is the only active color. The rule maps c c c to tid ( lab ) \operatorname{tid}(\operatorname{lab}) tid ( lab ) in λ t h r \lambda_{thr} λ t h r and to itself in λ r e p \lambda_{rep} λ r e p , and leaves Q i n Q_{in} Q in and Q o u t Q_{out} Q o u t unchanged, which do not contain c c c by Item (1), as c c c was inactive. This gives Items (1), (3) and (4), and Item (2) is immediate, as the uncolored events are unchanged.
Intro s b ( c 1 , c 2 ) \operatorname{Intro}_{sb}(c_1,c_2) Intro s b ( c 1 , c 2 ) . Write e i = χ − 1 ( c i ) e_i=\chi^{-1}(c_i) e i = χ − 1 ( c i ) . The new edge gives e 1 e_1 e 1 an outgoing and e 2 e_2 e 2 an incoming sb-edge, which the rule records, giving Item (1). By Item (3), the premise λ r e p ( c 1 ) ≠ λ r e p ( c 2 ) \lambda_{rep}(c_1)\ne\lambda_{rep}(c_2) λ r e p ( c 1 ) = λ r e p ( c 2 ) says that e 1 e_1 e 1 and e 2 e_2 e 2 lie in different components, which the new edge joins into one. The smallest active color of the joined component is the smaller of the two representatives, and the other components are unchanged, so merge \operatorname{merge} merge gives Item (3). Item (4) is immediate, and so is Item (2), as both endpoints of the new edge are colored.
Intro b ( c 1 , c 2 ) \operatorname{Intro}_{b}(c_1,c_2) Intro b ( c 1 , c 2 ) with b ∈ { r f , m b } b\in\{\mathrm{rf},\mathrm{mb}\} b ∈ { rf , mb } . The relation sb, the coloring and the state are unchanged. Forget ( c ) (c) ( c ) . Let e = χ − 1 ( c ) e = \chi^{-1}(c) e = χ − 1 ( c ) and t = λ t h r ( c ) t = \lambda_{\mathrm{thr}}(c) t = λ thr ( c ) . The event e e e becomes uncolored, and the edges and components are unchanged. So, Items (1) and (4) follow from the removal of c c c from λ t h r \lambda_{\mathrm{thr}} λ thr , Q i n Q_{\mathrm{in}} Q in and Q o u t Q_{\mathrm{out}} Q out . For Item (3), the colors whose smallest active color changes are those with λ r e p ( c ′ ) = c \lambda_{\mathrm{rep}}(c') = c λ rep ( c ′ ) = c , i.e., the other active colors of the component of e e e , whose new smallest active color is the smallest among them, as computed by drop . For Item (2), the only new uncolored event is e e e , whose edges are final. By Item (1), e e e is a first event of t t t iff c ∉ Q i n c \notin Q_{\mathrm{in}} c ∈ / Q in , in which case the rule adds t t t to Q f s t Q_{\mathrm{fst}} Q fst , and symmetrically for Q l s t Q_{\mathrm{lst}} Q lst . □
We now use this invariant to prove that A s b k A_{\mathrm{sb}}^{k} A sb k is correct.
Lemma E.3. For every k ∈ N k \in\mathbb{N} k ∈ N , there is a deterministic word automaton A s b k A_{\mathrm{sb}}^{k} A sb k with 2 O ( k log ( k ⋅ ∣ T i d ∣ ) + ∣ T i d ∣ ) 2^{O(k\log(k\cdot|\mathrm{Tid}|)+|\mathrm{Tid}|)} 2 O ( k l o g ( k ⋅ ∣ Tid ∣ ) + ∣ Tid ∣ ) states that accepts a closed w w w iff G s b w G^{w}_{\mathrm{sb}} G sb w is well-formed.
Proof. A state consists of two subsets of [ k + 1 ] [k+1] [ k + 1 ] , two subsets of T i d \mathrm{Tid} Tid , a partial map [ k + 1 ] ⇀ [ k + 1 ] [k+1] \rightharpoonup[k+1] [ k + 1 ] ⇀ [ k + 1 ] and a partial map [ k + 1 ] ⇀ T i d [k+1] \rightharpoonup\mathrm{Tid} [ k + 1 ] ⇀ Tid . So, there are at most 2 2 ( k + 1 ) ⋅ 2 2 ∣ T i d ∣ ⋅ ( k + 2 ) k + 1 ⋅ ( ∣ T i d ∣ + 1 ) k + 1 = 2 O ( k log ( k ⋅ ∣ T i d ∣ ) + ∣ T i d ∣ ) 2^{2(k+1)} \cdot2^{2|\mathrm{Tid}|} \cdot(k+2)^{k+1} \cdot(|\mathrm{Tid}|+1)^{k+1} = 2^{O(k\log(k\cdot|\mathrm{Tid}|)+|\mathrm{Tid}|)} 2 2 ( k + 1 ) ⋅ 2 2∣ Tid ∣ ⋅ ( k + 2 ) k + 1 ⋅ ( ∣ Tid ∣ + 1 ) k + 1 = 2 O ( k l o g ( k ⋅ ∣ Tid ∣ ) + ∣ Tid ∣ ) states. At most one rule applies to each state and letter, so A s b k A_{\mathrm{sb}}^{k} A sb k is deterministic.
Let w w w be closed.
Soundness. Suppose A s b k A_{\mathrm{sb}}^{k} A sb k accepts w w w . By Item (4) and the premise λ t h r ( c 1 ) = λ t h r ( c 2 ) \lambda_{\mathrm{thr}}(c_{1}) = \lambda_{\mathrm{thr}}(c_{2}) λ thr ( c 1 ) = λ thr ( c 2 ) , every sb-edge joins two events of the same thread, so every component lies within some E t E^{t} E t . By Item (1), the premises c 1 ∉ Q o u t c_{1} \notin Q_{\mathrm{out}} c 1 ∈ / Q out and c 2 ∉ Q i n c_{2} \notin Q_{\mathrm{in}} c 2 ∈ / Q in say that every event has at most one incoming and at most one outgoing sb-edge. By Item (3), the premise λ r e p ( c 1 ) ≠ λ r e p ( c 2 ) \lambda_{\mathrm{rep}}(c_{1}) \ne\lambda_{\mathrm{rep}}(c_{2}) λ rep ( c 1 ) = λ rep ( c 2 ) says that every edge joins two different components, so that every component is acyclic. An acyclic graph in which every event has at most one incoming and at most one outgoing edge is a sb-path, which has exactly one first event and one last event. Since w w w is closed, every event is forgotten at some point, and the rule for Forget rejects forgetting a first event of a thread that is already in Q f s t Q_{\mathrm{fst}} Q fst . So, by Item (2), each thread has at most one first event, and hence at most one component. So, each nonempty E t E^{t} E t is a single sb-path, i.e., Conditions (i) to (iii) hold.
Completeness. Conversely, suppose G s b w G^{w}_{\mathrm{sb}} G sb w is well-formed, i.e., each nonempty E t E^{t} E t forms a single sb-path. Consider the Intro s b ( c 1 , c 2 ) \operatorname{Intro}_{\mathrm{sb}}(c_{1}, c_{2}) Intro sb ( c 1 , c 2 ) that draws an edge e 1 → s b e 2 e_{1} \mathrel{\xrightarrow{\mathrm{sb}}} e_{2} e 1 sb e 2 . Its endpoints belong to the same thread, so λ t h r ( c 1 ) = λ t h r ( c 2 ) \lambda_{\mathrm{thr}}(c_{1}) = \lambda_{\mathrm{thr}}(c_{2}) λ thr ( c 1 ) = λ thr ( c 2 ) by Item (4). Each event has at most one incoming and at most one outgoing sb-edge, and each edge is drawn once, so c 1 ∉ Q o u t c_{1} \notin Q_{\mathrm{out}} c 1 ∈ / Q out and c 2 ∉ Q i n c_{2} \notin Q_{\mathrm{in}} c 2 ∈ / Q in by Item (1). Since none of the events sb-before e 1 e_{1} e 1 are connected to any of the events sb-after e 2 e_{2} e 2 , λ r e p ( c 1 ) ≠ λ r e p ( c 2 ) \lambda_{\mathrm{rep}}(c_{1}) \ne\lambda_{\mathrm{rep}}(c_{2}) λ rep ( c 1 ) = λ rep ( c 2 ) by Item (3). Finally, each thread has at most one first event and one last event, so, by Item (2), t ∉ Q f s t t \notin Q_{\mathrm{fst}} t ∈ / Q fst when its first event is forgotten, and t ∉ Q l s t t \notin Q_{\mathrm{lst}} t ∈ / Q lst when its last event is forgotten. So, the run exists, and it is accepting, as every state is. □
Well-formedness of r f \mathit{rf} rf . The main text only sketches A r f k A_{\mathrm{rf}}^{k} A rf k , so we first give its states and transition rules. By the definition of § 2.2 , r f \mathit{rf} rf is well-formed iff (i) every rf-edge goes from a write or RMW to a read or RMW, (ii) with the same location and value, and (iii) every read and RMW has exactly one incoming rf-edge. A state of A r f k A_{\mathrm{rf}}^{k} A rf k is a pair ⟨ λ l a b , Q s r c ⟩ \langle\lambda_{\mathrm{lab}}, Q_{\mathrm{src}}\rangle ⟨ λ lab , Q src ⟩ . Here, λ l a b : [ k + 1 ] → L a b \lambda_{\mathrm{lab}} : [k+1] \to\mathrm{Lab} λ lab : [ k + 1 ] → Lab maps each active color to the label of its event, and Q s r c ⊆ [ k + 1 ] Q_{\mathrm{src}} \subseteq[k+1] Q src ⊆ [ k + 1 ] is the set of active colors whose events are reads or RMWs without an incoming rf-edge yet. Intuitively, the labels in λ l a b \lambda_{\mathrm{lab}} λ lab suffice to check Conditions (i) and (ii) when an rf-edge is drawn. The set Q s r c Q_{\mathrm{src}} Q src is used to check Condition (iii): a read or RMW cannot receive a second incoming rf-edge, and cannot be forgotten before it receives one. The initial state and the unique accepting state are both ⟨ ∅ , ∅ ⟩ \langle\varnothing, \varnothing\rangle ⟨ ∅ , ∅ ⟩ , and the transition rules are the following.
op = Intro ( lab , c ) λ lab ′ = λ lab ∪ { c → lab } Q src ′ = Q src ∪ { c } if opr ( lab ) ∈ { r , rmw } , and Q src ′ = Q src otherwise ⟨ λ lab , Q src ⟩ → op ⟨ λ lab ′ , Q src ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intro}(\operatorname{lab},c) && \lambda'_{\operatorname{lab}} = \lambda_{\operatorname{lab}} \cup\{c \to\operatorname{lab}\}\\
&&& Q'_{\operatorname{src}} = Q_{\operatorname{src}} \cup\{c\}\text{ if }\operatorname{opr}(\operatorname{lab}) \in\{r,\operatorname{rmw}\},\text{ and }Q'_{\operatorname{src}} = Q_{\operatorname{src}}\text{ otherwise}\\
&&& \langle\lambda_{\operatorname{lab}},Q_{\operatorname{src}}\rangle\xrightarrow{\operatorname{op}} \langle\lambda'_{\operatorname{lab}},Q'_{\operatorname{src}}\rangle
\end{aligned} op = Intro ( lab , c ) λ lab ′ = λ lab ∪ { c → lab } Q src ′ = Q src ∪ { c } if opr ( lab ) ∈ { r , rmw } , and Q src ′ = Q src otherwise ⟨ λ lab , Q src ⟩ op ⟨ λ lab ′ , Q src ′ ⟩
op = Forget ( c ) c ∉ Q src λ lab ′ = λ lab ∖ { c → λ lab ( c ) } ⟨ λ lab , Q src ⟩ → op ⟨ λ lab ′ , Q src ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Forget}(c) && c \notin Q_{\operatorname{src}}\\
&&& \lambda'_{\operatorname{lab}} = \lambda_{\operatorname{lab}} \setminus\{c \to\lambda_{\operatorname{lab}}(c)\}\\
&&& \langle\lambda_{\operatorname{lab}},Q_{\operatorname{src}}\rangle\xrightarrow{\operatorname{op}} \langle\lambda'_{\operatorname{lab}},Q_{\operatorname{src}}\rangle
\end{aligned} op = Forget ( c ) c ∈ / Q src λ lab ′ = λ lab ∖ { c → λ lab ( c )} ⟨ λ lab , Q src ⟩ op ⟨ λ lab ′ , Q src ⟩
op = Intro rf ( c 1 , c 2 ) opr ( λ lab ( c 1 ) ) ∈ { w , rmw } c 2 ∈ Q src loc ( λ lab ( c 1 ) ) = loc ( λ lab ( c 2 ) ) val w ( λ lab ( c 1 ) ) = val r ( λ lab ( c 2 ) ) Q src ′ = Q src ∖ { c 2 } ⟨ λ lab , Q src ⟩ → op ⟨ λ lab , Q src ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intro}_{\operatorname{rf}}(c_1,c_2) && \operatorname{opr}(\lambda_{\operatorname{lab}}(c_1)) \in\{w,\operatorname{rmw}\}\\
&&& c_2 \in Q_{\operatorname{src}} && \operatorname{loc}(\lambda_{\operatorname{lab}}(c_1)) = \operatorname{loc}(\lambda_{\operatorname{lab}}(c_2))\\
&&& \operatorname{val}_{w}(\lambda_{\operatorname{lab}}(c_1)) = \operatorname{val}_{r}(\lambda_{\operatorname{lab}}(c_2)) && Q'_{\operatorname{src}} = Q_{\operatorname{src}} \setminus\{c_2\}\\
&&& \langle\lambda_{\operatorname{lab}},Q_{\operatorname{src}}\rangle\xrightarrow{\operatorname{op}} \langle\lambda_{\operatorname{lab}},Q'_{\operatorname{src}}\rangle
\end{aligned} op = Intro rf ( c 1 , c 2 ) opr ( λ lab ( c 1 )) ∈ { w , rmw } c 2 ∈ Q src val w ( λ lab ( c 1 )) = val r ( λ lab ( c 2 )) ⟨ λ lab , Q src ⟩ op ⟨ λ lab , Q src ′ ⟩ loc ( λ lab ( c 1 )) = loc ( λ lab ( c 2 )) Q src ′ = Q src ∖ { c 2 }
op = Intro b ( c 1 , c 2 ) b ∈ { sb , mb } ⟨ λ lab , Q src ⟩ → op ⟨ λ lab , Q src ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intro}_{b}(c_1,c_2) && b \in\{\operatorname{sb},\operatorname{mb}\}\\
&&& \langle\lambda_{\operatorname{lab}},Q_{\operatorname{src}}\rangle\xrightarrow{\operatorname{op}} \langle\lambda_{\operatorname{lab}},Q_{\operatorname{src}}\rangle
\end{aligned} op = Intro b ( c 1 , c 2 ) b ∈ { sb , mb } ⟨ λ lab , Q src ⟩ op ⟨ λ lab , Q src ⟩
We now prove that A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k is correct.
Lemma E.4. For every k ∈ N k \in\mathbb{N} k ∈ N , there is a deterministic word automaton A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k with 2 O ( k log ∣ Lab ∣ ) 2^{O(k\log|\operatorname{Lab}|)} 2 O ( k l o g ∣ Lab ∣ ) states that accepts a closed w w w iff G w . rf G^{w}.\operatorname{rf} G w . rf is well-formed.
Proof. A state of A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k is a partial map [ k + 1 ] ⇀ Lab [k+1] \rightharpoonup\operatorname{Lab} [ k + 1 ] ⇀ Lab together with a subset of [ k + 1 ] [k+1] [ k + 1 ] . So, there are ( ∣ Lab ∣ + 1 ) k + 1 = 2 O ( k log ∣ Lab ∣ ) (|\operatorname{Lab}|+1)^{k+1}=2^{O(k\log|\operatorname{Lab}|)} ( ∣ Lab ∣ + 1 ) k + 1 = 2 O ( k l o g ∣ Lab ∣ ) states. Moreover, exactly one rule applies to each state and letter, so A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k is deterministic.
By induction on ∣ w ∣ |w| ∣ w ∣ , if A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k has a run on a well-formed w w w , then λ lab ( c ) = lab ( χ − 1 ( c ) ) \lambda_{\operatorname{lab}}(c)=\operatorname{lab}(\chi^{-1}(c)) λ lab ( c ) = lab ( χ − 1 ( c )) for every active color c c c , and Q src Q_{\operatorname{src}} Q src is the set of active colors whose events are reads or RMWs without an incoming rf \operatorname{rf} rf -edge in G w G^{w} G w . The first claim follows directly from the rules for Intro and Forget. For the second, a color enters Q src Q_{\operatorname{src}} Q src when a read or RMW is introduced, and leaves Q src Q_{\operatorname{src}} Q src when its incoming rf \operatorname{rf} rf -edge is drawn. Moreover, the rule for Forget never removes a color of Q src Q_{\operatorname{src}} Q src .
For soundness, suppose that A rf k \mathcal{A}^{k}_{\operatorname{rf}} A rf k accepts a closed w w w . The premises of the rule for Intro rf ( c 1 , c 2 ) \operatorname{Intro}_{\operatorname{rf}}(c_1,c_2) Intro rf ( c 1 , c 2 ) check that the source is a write or RMW, that the target is a read or RMW without an incoming rf \operatorname{rf} rf -edge yet, and that both have the same location and value. This gives Conditions (i) and (ii). For Condition (iii), a read or RMW cannot receive two incoming rf \operatorname{rf} rf -edges, as its color leaves Q src Q_{\operatorname{src}} Q src after the first one. It also cannot receive none. Otherwise, its color would stay in Q src Q_{\operatorname{src}} Q src , and the rule for Forget would prevent it from ever being forgotten, which is impossible as w w w is closed.
For completeness, suppose conversely that G w . rf G^{w}.\operatorname{rf} G w . rf satisfies Conditions (i) to (iii). Consider an operation that draws an rf \operatorname{rf} rf -edge. Its premises on labels hold by Conditions (i) and (ii). Its target has no incoming rf \operatorname{rf} rf -edge yet, as it has exactly one by Condition (iii), and each edge is drawn only once. Moreover, every read or RMW receives its incoming rf \operatorname{rf} rf -edge before it is forgotten, since this edge can only be drawn while it is colored. So, the premise c ∉ Q src c \notin Q_{\operatorname{src}} c ∈ / Q src of the rule for Forget always holds. Finally, the run ends in ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ , as w w w is closed.
Well-formedness of mb \operatorname{mb} mb . Similarly, the main text only describes A mb k \mathcal{A}^{k}_{\operatorname{mb}} A mb k as a variant of A sb k \mathcal{A}^{k}_{\operatorname{sb}} A sb k , so we first give its rules. The construction is the same as for A sb k \mathcal{A}^{k}_{\operatorname{sb}} A sb k , with locations in place of threads, and restricted to writes and RMWs. Indeed, mb \operatorname{mb} mb is well-formed iff, for each location, (i) all writes and RMWs but one have exactly one incoming mb \operatorname{mb} mb -edge, and that one has none, (ii) all writes and RMWs but one have exactly one outgoing mb \operatorname{mb} mb -edge, and that one has none, and (iii) all writes and RMWs are connected. A state is a tuple ⟨ Q in , Q out , Q fst , λ rep , λ loc ⟩ \langle Q_{\operatorname{in}},Q_{\operatorname{out}},Q_{\operatorname{fst}},\lambda_{\operatorname{rep}},\lambda_{\operatorname{loc}}\rangle ⟨ Q in , Q out , Q fst , λ rep , λ loc ⟩ with Q in , Q out , Q fst , Q lst ⊆ Loc Q_{\operatorname{in}},Q_{\operatorname{out}},Q_{\operatorname{fst}},Q_{\operatorname{lst}} \subseteq\operatorname{Loc} Q in , Q out , Q fst , Q lst ⊆ Loc , λ rep : [ k + 1 ] → [ k + 1 ] \lambda_{\operatorname{rep}}:[k+1]\to[k+1] λ rep : [ k + 1 ] → [ k + 1 ] and λ loc : [ k + 1 ] → Loc \lambda_{\operatorname{loc}}:[k+1]\to\operatorname{Loc} λ loc : [ k + 1 ] → Loc . The components have the same meaning as for A sb k \mathcal{A}^{k}_{\operatorname{sb}} A sb k , but for mb \operatorname{mb} mb , and for the writes and RMWs on each location instead of the events of each thread. Since reads and fences are not part of any mb \operatorname{mb} mb -chain, λ rep \lambda_{\operatorname{rep}} λ rep and λ loc \lambda_{\operatorname{loc}} λ loc are only defined on the colors of writes and RMWs. So, the rules for Intro and Forget ignore reads and fences. The initial state is ⟨ ∅ , ∅ , ∅ , ∅ , ∅ ⟩ \langle\varnothing,\varnothing,\varnothing,\varnothing,\varnothing\rangle ⟨ ∅ , ∅ , ∅ , ∅ , ∅ ⟩ , and every state is accepting. We reuse the functions Merge and Drop of A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , and the transition rules are the following, where the components that are not mentioned are unchanged.
op = Intro ( lab , c ) opr ( lab ) ∈ { w , r m w } λ r e p ′ = λ r e p ∪ { c ↦ c } λ l o c ′ = λ l o c ∪ { c ↦ loc ( lab ) } ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ l o c ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ l o c ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intro}(\operatorname{lab},c) && \operatorname{opr}(\operatorname{lab}) \in\{\mathrm{w},\mathrm{rmw}\}\\
\lambda'_{\mathrm{rep}} &= \lambda_{\mathrm{rep}} \cup\{c \mapsto c\} && \lambda'_{\mathrm{loc}} = \lambda_{\mathrm{loc}} \cup\{c \mapsto\operatorname{loc}(\operatorname{lab})\}\\
\langle Q_{\mathrm{in}},Q_{\mathrm{out}},Q_{\mathrm{fst}},Q_{\mathrm{lst}},\lambda_{\mathrm{rep}},\lambda_{\mathrm{loc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{in}},Q'_{\mathrm{out}},Q'_{\mathrm{fst}},Q'_{\mathrm{lst}},\lambda'_{\mathrm{rep}},\lambda'_{\mathrm{loc}}\rangle
\end{aligned} op λ rep ′ ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ loc ⟩ = Intro ( lab , c ) = λ rep ∪ { c ↦ c } op ⟨ Q in ′ , Q out ′ , Q fst ′ , Q lst ′ , λ rep ′ , λ loc ′ ⟩ opr ( lab ) ∈ { w , rmw } λ loc ′ = λ loc ∪ { c ↦ loc ( lab )}
op = Forget ( c ) c ∈ dom ( λ l o c ) x = λ l o c ( c ) c ∉ Q i n ⇒ x ∉ Q f s t c ∉ Q o u t ⇒ x ∉ Q l s t Q f s t ′ = Q f s t ∪ { x ∣ c ∉ Q i n } Q l s t ′ = Q l s t ∪ { x ∣ c ∉ Q o u t } Q i n ′ = Q i n ∖ { c } Q o u t ′ = Q o u t ∖ { c } λ r e p ′ = drop ( c , λ r e p ) λ l o c ′ = λ l o c ∖ { c ↦ x } ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ l o c ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ l o c ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Forget}(c) && c \in\operatorname{dom}(\lambda_{\mathrm{loc})} && x=\lambda_{\mathrm{loc}}(c) && c \notin Q_{\mathrm{in}} \Rightarrow x \notin Q_{\mathrm{fst}} && c \notin Q_{\mathrm{out}} \Rightarrow x \notin Q_{\mathrm{lst}}\\
Q'_{\mathrm{fst}} &= Q_{\mathrm{fst}} \cup\{x \mid c \notin Q_{\mathrm{in}}\} && Q'_{\mathrm{lst}} = Q_{\mathrm{lst}} \cup\{x \mid c \notin Q_{\mathrm{out}}\} && Q'_{\mathrm{in}}=Q_{\mathrm{in}}\setminus\{c\} && Q'_{\mathrm{out}}=Q_{\mathrm{out}}\setminus\{c\}\\
\lambda'_{\mathrm{rep}} &= \operatorname{drop}(c,\lambda_{\mathrm{rep}}) && \lambda'_{\mathrm{loc}}=\lambda_{\mathrm{loc}}\setminus\{c\mapsto x\}\\
\langle Q_{\mathrm{in}},Q_{\mathrm{out}},Q_{\mathrm{fst}},Q_{\mathrm{lst}},\lambda_{\mathrm{rep}},\lambda_{\mathrm{loc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{in}},Q'_{\mathrm{out}},Q'_{\mathrm{fst}},Q'_{\mathrm{lst}},\lambda'_{\mathrm{rep}},\lambda'_{\mathrm{loc}}\rangle
\end{aligned} op Q fst ′ λ rep ′ ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ loc ⟩ = Forget ( c ) = Q fst ∪ { x ∣ c ∈ / Q in } = drop ( c , λ rep ) op ⟨ Q in ′ , Q out ′ , Q fst ′ , Q lst ′ , λ rep ′ , λ loc ′ ⟩ c ∈ dom ( λ loc ) Q lst ′ = Q lst ∪ { x ∣ c ∈ / Q out } λ loc ′ = λ loc ∖ { c ↦ x } x = λ loc ( c ) Q in ′ = Q in ∖ { c } c ∈ / Q in ⇒ x ∈ / Q fst Q out ′ = Q out ∖ { c } c ∈ / Q out ⇒ x ∈ / Q lst
op = Intromb ( c 1 , c 2 ) c 1 , c 2 ∈ dom ( λ l o c ) λ l o c ( c 1 ) = λ l o c ( c 2 ) c 1 ∉ Q o u t c 2 ∉ Q i n λ r e p ( c 1 ) ≠ λ r e p ( c 2 ) Q o u t ′ = Q o u t ∪ { c 1 } Q i n ′ = Q i n ∪ { c 2 } λ r e p ′ = merge ( c 1 , c 2 , λ r e p ) ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ l o c ⟩ → op ⟨ Q i n ′ , Q o u t ′ , Q f s t ′ , Q l s t ′ , λ r e p ′ , λ l o c ′ ⟩ \begin{aligned}
\operatorname{op} &= \operatorname{Intromb}(c_1,c_2) && c_1,c_2\in\operatorname{dom}(\lambda_{\mathrm{loc}}) && \lambda_{\mathrm{loc}}(c_1)=\lambda_{\mathrm{loc}}(c_2) && c_1\notin Q_{\mathrm{out}} && c_2\notin Q_{\mathrm{in}}\\
&&& \lambda_{\mathrm{rep}}(c_1)\ne\lambda_{\mathrm{rep}}(c_2) && Q'_{\mathrm{out}}=Q_{\mathrm{out}}\cup\{c_1\} && Q'_{\mathrm{in}}=Q_{\mathrm{in}}\cup\{c_2\} && \lambda'_{\mathrm{rep}}=\operatorname{merge}(c_1,c_2,\lambda_{\mathrm{rep}})\\
\langle Q_{\mathrm{in}},Q_{\mathrm{out}},Q_{\mathrm{fst}},Q_{\mathrm{lst}},\lambda_{\mathrm{rep}},\lambda_{\mathrm{loc}}\rangle&\xrightarrow{\operatorname{op}} \langle Q'_{\mathrm{in}},Q'_{\mathrm{out}},Q'_{\mathrm{fst}},Q'_{\mathrm{lst}},\lambda'_{\mathrm{rep}},\lambda'_{\mathrm{loc}}\rangle
\end{aligned} op ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ loc ⟩ = Intromb ( c 1 , c 2 ) op ⟨ Q in ′ , Q out ′ , Q fst ′ , Q lst ′ , λ rep ′ , λ loc ′ ⟩ c 1 , c 2 ∈ dom ( λ loc ) λ rep ( c 1 ) = λ rep ( c 2 ) λ loc ( c 1 ) = λ loc ( c 2 ) Q out ′ = Q out ∪ { c 1 } c 1 ∈ / Q out Q in ′ = Q in ∪ { c 2 } c 2 ∈ / Q in λ rep ′ = merge ( c 1 , c 2 , λ rep )
op = Intro ( lab , c ) opr ( lab ) ∈ { r , f } q → op q op = Forget ( c ) c ∉ dom ( λ l o c ) q → op q op = Intro b ( c 1 , c 2 ) b ∈ { s b , r f } q → op q \begin{aligned}
\operatorname{op}&=\operatorname{Intro}(\operatorname{lab},c) && \operatorname{opr}(\operatorname{lab})\in\{\mathrm{r},\mathrm{f}\}\\
q&\xrightarrow{\operatorname{op}}q\\
\operatorname{op}&=\operatorname{Forget}(c) && c\notin\operatorname{dom}(\lambda_{\mathrm{loc}})\\
q&\xrightarrow{\operatorname{op}}q\\
\operatorname{op}&=\operatorname{Intro}_{b}(c_1,c_2) && b\in\{\mathrm{sb},\mathrm{rf}\}\\
q&\xrightarrow{\operatorname{op}}q
\end{aligned} op q op q op q = Intro ( lab , c ) op q = Forget ( c ) op q = Intro b ( c 1 , c 2 ) op q opr ( lab ) ∈ { r , f } c ∈ / dom ( λ loc ) b ∈ { sb , rf }
where q = ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ l o c ⟩ q=\langle Q_{\mathrm{in}},Q_{\mathrm{out}},Q_{\mathrm{fst}},Q_{\mathrm{lst}},\lambda_{\mathrm{rep}},\lambda_{\mathrm{loc}}\rangle q = ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ loc ⟩ .
The correctness of A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k is thus similar to A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k .
Lemma E.5. For every k ∈ N k\in\mathbb{N} k ∈ N , there is a deterministic word automaton A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k with 2 O ( k log ( k ⋅ ∣ L o c ∣ ) + ∣ L o c ∣ ) 2^{O(k\log(k\cdot|\mathrm{Loc}|)+|\mathrm{Loc}|)} 2 O ( k l o g ( k ⋅ ∣ Loc ∣ ) + ∣ Loc ∣ ) states that accepts a closed w w w iff G m b w G^{w}_{\mathrm{mb}} G mb w is well-formed.
Proof. The number of states is that of Lemma E.3 , with Loc in place of Tid. For correctness, Lemma E.2 and the proof of Lemma E.3 carry over, with m b \mathrm{mb} mb in place of s b \mathrm{sb} sb , the writes and RMWs on each location in place of the events of each thread. It remains to check that reads are handled correctly. The premise c 1 , c 2 ∈ dom ( λ l o c ) c_1,c_2\in\operatorname{dom}(\lambda_{\mathrm{loc}}) c 1 , c 2 ∈ dom ( λ loc ) of the rule for Intro m b \operatorname{Intro}_{\mathrm{mb}} Intro mb rejects every m b \mathrm{mb} mb -edge with a read as an endpoint, which well-formedness of m b \mathrm{mb} mb also forbids. Moreover, the rules for Intro \operatorname{Intro} Intro and Forget \operatorname{Forget} Forget leave the state unchanged for reads. So, reads never appear in Q i n Q_{\mathrm{in}} Q in or Q o u t Q_{\mathrm{out}} Q out , never add a location to Q f s t Q_{\mathrm{fst}} Q fst or Q l s t Q_{\mathrm{lst}} Q lst , and never appear in dom ( λ r e p ) \operatorname{dom}(\lambda_{\mathrm{rep}}) dom ( λ rep ) or dom ( λ l o c ) \operatorname{dom}(\lambda_{\mathrm{loc}}) dom ( λ loc ) .
The product. Finally, A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k is the product of the four automata above, which proves Lemma 5.1 .
Lemma 5.1. For every k ∈ N k\in\mathbb{N} k ∈ N , there is a deterministic automaton A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k with 2 O ( k 2 + k log ∣ L a b ∣ + ∣ T i d ∣ + ∣ L o c ∣ ) 2^{O(k^{2}+k\log|\mathrm{Lab}|+|\mathrm{Tid}|+|\mathrm{Loc}|)} 2 O ( k 2 + k l o g ∣ Lab ∣ + ∣ Tid ∣ + ∣ Loc ∣ ) states that accepts w ∈ Ops ( k + 1 ) w\in\operatorname{Ops}(k+1) w ∈ Ops ( k + 1 ) iff w w w is closed and G w G^{w} G w is an execution graph.
Proof. Let A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k be the product of A f o r m k \mathcal{A}^{k}_{\mathrm{form}} A form k , A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k and A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k . By Lemma E.1, A f o r m k \mathcal{A}^{k}_{\mathrm{form}} A form k accepts w w w iff w w w is closed. For such w w w , by Lemmas E.3 to E.5, the other three automata accept w w w iff G s b w G^{w}_{\mathrm{sb}} G sb w , G r f w G^{w}_{\mathrm{rf}} G rf w and G m b w G^{w}_{\mathrm{mb}} G mb w are well-formed. So, A w f k \mathcal{A}^{k}_{\mathrm{wf}} A wf k accepts w w w iff w w w is closed, and G w G^{w} G w is an execution graph. Its number of states is the product of those components, which gives the stated bound, using k log k ≤ k 2 k\log k\le k^{2} k log k ≤ k 2 and ∣ T i d ∣ , ∣ L o c ∣ ≤ ∣ L a b ∣ |\mathrm{Tid}|,|\mathrm{Loc}|\le|\mathrm{Lab}| ∣ Tid ∣ , ∣ Loc ∣ ≤ ∣ Lab ∣ .
Proofs of SUBSEC:AUTPROG
In this subsection, we prove that A p k \mathcal{A}^{k}_{p} A p k recognizes the graphs of P (Lemma 5.2 ). Fix P as in § 5.2 , with PSeq t = ⟨ Q t , L a b † , Δ t , init t ⟩ \operatorname{PSeq}_{t}=\langle Q_{t},\mathrm{Lab}^{\dagger},\Delta_{t},\operatorname{init}_{t}\rangle PSeq t = ⟨ Q t , Lab † , Δ t , init t ⟩ for each t ∈ T i d t\in\mathrm{Tid} t ∈ Tid . For states u u u and v v v of the same PSeq t \operatorname{PSeq}_{t} PSeq t , we write ϵ \epsilon ϵ -reach( u , v ) (u,v) ( u , v ) when P s e q t \mathrm{Pseq}_t Pseq t has a (possibly empty) path of silent transitions from u u u to v v v . The initial state and the unique accepting state of A P k \mathcal{A}^{k}_{P} A P k are both ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ , and its rules are the following.
o p = I n t r o ( l a b , c ) δ ∈ Δ t i d ( l a b ) l a b ( δ ) = l a b Q s r c ′ = Q s r c ∪ { c } λ t r ′ = λ t r ∪ { c ↦ δ } ⟨ Q s r c , λ t r ⟩ → o p ⟨ Q s r c ′ , λ t r ′ ⟩ o p = F o r g e t ( c ) c ∉ Q s r c λ t r ′ = λ t r ∖ { c ↦ λ t r ( c ) } ⟨ Q s r c , λ t r ⟩ → o p ⟨ Q s r c , λ t r ′ ⟩ o p = I n t r o b ( c 1 , c 2 ) b ∈ { r f , m b } ⟨ Q s r c , λ t r ⟩ → o p ⟨ Q s r c , λ t r ⟩ o p = F o r g e t ( c ) c ∈ Q s r c ϵ -reach ( i n i t t i d ( l a b ( λ t r ( c ) ) ) , s r c ( λ t r ( c ) ) ) Q s r c ′ = Q s r c ∖ { c } λ t r ′ = λ t r ∖ { c ↦ λ t r ( c ) } ⟨ Q s r c , λ t r ⟩ → o p ⟨ Q s r c ′ , λ t r ′ ⟩ o p = I n t r o s b ( c 1 , c 2 ) c 2 ∈ Q s r c ϵ -reach ( t g t ( λ t r ( c 1 ) ) , s r c ( λ t r ( c 2 ) ) ) Q s r c ′ = Q s r c ∖ { c 2 } ⟨ Q s r c , λ t r ⟩ → o p ⟨ Q s r c ′ , λ t r ⟩ \begin{array}{ccc}
\begin{gathered}
\mathrm{op}=\mathrm{Intro}(\mathrm{lab},c)\\
\delta\in\Delta_{\mathrm{tid}(\mathrm{lab})}\quad\mathrm{lab}(\delta)=\mathrm{lab}\\
Q'_{\mathrm{src}}=Q_{\mathrm{src}}\cup\{c\}\quad\lambda'_{\mathrm{tr}}=\lambda_{\mathrm{tr}}\cup\{c\mapsto\delta\}\\
\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle\xrightarrow{\mathrm{op}}\langle Q'_{\mathrm{src}},\lambda'_{\mathrm{tr}}\rangle
\end{gathered}
\qquad& \qquad
\begin{gathered}
\mathrm{op}=\mathrm{Forget}(c)\quad c\notin Q_{\mathrm{src}}\\
\lambda'_{\mathrm{tr}}=\lambda_{\mathrm{tr}}\setminus\{c\mapsto\lambda_{\mathrm{tr}}(c)\}\\
\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle\xrightarrow{\mathrm{op}}\langle Q_{\mathrm{src}},\lambda'_{\mathrm{tr}}\rangle
\end{gathered}
\qquad& \qquad
\begin{gathered}
\mathrm{op}=\mathrm{Intro}_{b}(c_{1},c_{2})\\
b\in\{\mathrm{rf},\mathrm{mb}\}\\
\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle\xrightarrow{\mathrm{op}}\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle
\end{gathered}
\\[1.5em]
\begin{gathered}
\mathrm{op}=\mathrm{Forget}(c)\quad c\in Q_{\mathrm{src}}\\
\epsilon\text{-reach}(\mathrm{init}_{\mathrm{tid}}(\mathrm{lab}(\lambda_{\mathrm{tr}}(c))),\mathrm{src}(\lambda_{\mathrm{tr}}(c)))\\
Q'_{\mathrm{src}}=Q_{\mathrm{src}}\setminus\{c\}\quad\lambda'_{\mathrm{tr}}=\lambda_{\mathrm{tr}}\setminus\{c\mapsto\lambda_{\mathrm{tr}}(c)\}\\
\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle\xrightarrow{\mathrm{op}}\langle Q'_{\mathrm{src}},\lambda'_{\mathrm{tr}}\rangle
\end{gathered}
\qquad& \qquad
\begin{gathered}
\mathrm{op}=\mathrm{Intro}_{\mathrm{sb}}(c_{1},c_{2})\quad c_{2}\in Q_{\mathrm{src}}\\
\epsilon\text{-reach}(\mathrm{tgt}(\lambda_{\mathrm{tr}}(c_{1})),\mathrm{src}(\lambda_{\mathrm{tr}}(c_{2})))\\
Q'_{\mathrm{src}}=Q_{\mathrm{src}}\setminus\{c_{2}\}\\
\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle\xrightarrow{\mathrm{op}}\langle Q'_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle
\end{gathered}
\qquad& \\
\end{array} op = Intro ( lab , c ) δ ∈ Δ tid ( lab ) lab ( δ ) = lab Q src ′ = Q src ∪ { c } λ tr ′ = λ tr ∪ { c ↦ δ } ⟨ Q src , λ tr ⟩ op ⟨ Q src ′ , λ tr ′ ⟩ op = Forget ( c ) c ∈ Q src ϵ -reach ( init tid ( lab ( λ tr ( c ))) , src ( λ tr ( c ))) Q src ′ = Q src ∖ { c } λ tr ′ = λ tr ∖ { c ↦ λ tr ( c )} ⟨ Q src , λ tr ⟩ op ⟨ Q src ′ , λ tr ′ ⟩ op = Forget ( c ) c ∈ / Q src λ tr ′ = λ tr ∖ { c ↦ λ tr ( c )} ⟨ Q src , λ tr ⟩ op ⟨ Q src , λ tr ′ ⟩ op = Intro sb ( c 1 , c 2 ) c 2 ∈ Q src ϵ -reach ( tgt ( λ tr ( c 1 )) , src ( λ tr ( c 2 ))) Q src ′ = Q src ∖ { c 2 } ⟨ Q src , λ tr ⟩ op ⟨ Q src ′ , λ tr ⟩ op = Intro b ( c 1 , c 2 ) b ∈ { rf , mb } ⟨ Q src , λ tr ⟩ op ⟨ Q src , λ tr ⟩
Throughout, w w w is well-formed and G c w = ⟨ E , s b , r f , m b , χ ⟩ G^{w}_{c}=\langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb},\chi\rangle G c w = ⟨ E , sb , rf , mb , χ ⟩ . The automaton A P k \mathcal{A}^{k}_{P} A P k is nondeterministic, so its state after w w w depends on the run and not only on w w w . Given a run ρ \rho ρ of A P k \mathcal{A}^{k}_{P} A P k on w w w , we write μ ρ ( e ) \mu_{\rho}(e) μ ρ ( e ) for the transition δ \delta δ that the I n t r o \mathrm{Intro} Intro rule chose at the operation introducing e ∈ E e\in E e ∈ E , and μ \mu μ when ρ \rho ρ is clear from the context. The following lemma describes the state reached by such a run, together with the transitions it chose.
Lemma E.6. Let ρ \rho ρ be a run of A P k \mathcal{A}^{k}_{P} A P k on a well-formed w w w , reaching ⟨ Q s r c , λ t r ⟩ \langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle ⟨ Q src , λ tr ⟩ , and let μ = μ ρ \mu=\mu_{\rho} μ = μ ρ . Then
μ ( e ) ∈ Δ t i d ( e ) \mu(e)\in\Delta_{\mathrm{tid}(e)} μ ( e ) ∈ Δ tid ( e ) and l a b ( μ ( e ) ) = l a b ( e ) \mathrm{lab}(\mu(e))=\mathrm{lab}(e) lab ( μ ( e )) = lab ( e ) for every e ∈ E e\in E e ∈ E ;
dom ( λ t r ) = img ( χ ) \operatorname{dom}(\lambda_{\mathrm{tr}})=\operatorname{img}(\chi) dom ( λ tr ) = img ( χ ) and λ t r ( c ) = μ ( χ − 1 ( c ) ) \lambda_{\mathrm{tr}}(c)=\mu(\chi^{-1}(c)) λ tr ( c ) = μ ( χ − 1 ( c )) ;
Q s r c Q_{\mathrm{src}} Q src is the set of c ∈ img ( χ ) c\in\operatorname{img}(\chi) c ∈ img ( χ ) such that χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) has no incoming s b \mathrm{sb} sb -edge;
ϵ \epsilon ϵ -reach( t g t ( μ ( e 1 ) ) , s r c ( μ ( e 2 ) ) ) (\mathrm{tgt}(\mu(e_{1})),\mathrm{src}(\mu(e_{2}))) ( tgt ( μ ( e 1 )) , src ( μ ( e 2 ))) for every e 1 → s b e 2 e_{1}\xrightarrow{\mathrm{sb}}e_{2} e 1 sb e 2 ;
ϵ \epsilon ϵ -reach( i n i t t i d ( e ) , s r c ( μ ( e ) ) ) (\mathrm{init}_{\mathrm{tid}}(e),\mathrm{src}(\mu(e))) ( init tid ( e ) , src ( μ ( e ))) for every uncolored e ∈ E e\in E e ∈ E with no incoming s b \mathrm{sb} sb -edge.
Proof. By induction on ∣ w ∣ |w| ∣ w ∣ . The empty word gives ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ and G c ∅ = ⊥ G^{\varnothing}_{c}=\bot G c ∅ = ⊥ , for which all five claims hold vacuously. For the inductive step, let o p \mathrm{op} op be the last operation of w w w and assume the claims for the preceding prefix. Note that an uncolored event never receives a new s b \mathrm{sb} sb -edge, as I n t r o s b \mathrm{Intro}_{\mathrm{sb}} Intro sb only joins colored events. So, Items (4) and (5) are never invalidated for events that are already uncolored.
I n t r o ( l a b , c ) \mathrm{Intro}(\mathrm{lab},c) Intro ( lab , c ) . Let e e e be the introduced event and δ \delta δ the transition chosen, so μ ( e ) = δ \mu(e)=\delta μ ( e ) = δ . The premises δ ∈ Δ t i d ( l a b ) \delta\in\Delta_{\mathrm{tid}(\mathrm{lab})} δ ∈ Δ tid ( lab ) and l a b ( δ ) = l a b \mathrm{lab}(\delta)=\mathrm{lab} lab ( δ ) = lab give Item (1), as l a b ( e ) = l a b \mathrm{lab}(e)=\mathrm{lab} lab ( e ) = lab . The rule sets λ t r ′ = λ t r ∪ { c → δ } \lambda'_{\mathrm{tr}}=\lambda_{\mathrm{tr}}\cup\{c\to\delta\} λ tr ′ = λ tr ∪ { c → δ } , giving Item (2). The event e e e is colored and has no s b \mathrm{sb} sb -edge, so adding c c c to Q s r c Q_{\mathrm{src}} Q src gives Item (3), and Items (4) and (5) are unaffected.
I n t r o s b ( c 1 , c 2 ) \mathrm{Intro}_{\mathrm{sb}}(c_{1},c_{2}) Intro sb ( c 1 , c 2 ) . Write e i = χ − 1 ( c i ) e_{i}=\chi^{-1}(c_{i}) e i = χ − 1 ( c i ) . The operation adds the edge e 1 → s b e 2 e_{1}\xrightarrow{\mathrm{sb}}e_{2} e 1 sb e 2 , and the premise ϵ \epsilon ϵ -reach( t g t ( λ t r ( c 1 ) ) , s r c ( λ t r ( c 2 ) ) ) (\mathrm{tgt}(\lambda_{\mathrm{tr}}(c_{1})),\mathrm{src}(\lambda_{\mathrm{tr}}(c_{2}))) ( tgt ( λ tr ( c 1 )) , src ( λ tr ( c 2 ))) is, by Item (2), the instance of Item (4) for that edge. After the operation e 2 e_{2} e 2 has an incoming s b \mathrm{sb} sb -edge, and the rule removes c 2 c_{2} c 2 from Q s r c Q_{\mathrm{src}} Q src , giving Item (3). Items (1), (2) and (5) are unaffected, as μ \mu μ , λ t r \lambda_{\mathrm{tr}} λ tr and the coloring are unchanged.
F o r g e t ( c ) \mathrm{Forget}(c) Forget ( c ) . Let e = χ − 1 ( c ) e=\chi^{-1}(c) e = χ − 1 ( c ) . Both rules remove c c c from λ t r \lambda_{\mathrm{tr}} λ tr and from Q s r c Q_{\mathrm{src}} Q src , which gives Items (2) and (3). Since e e e is now uncolored, Item (5) requires ϵ \epsilon ϵ -reach( i n i t t i d ( e ) , s r c ( μ ( e ) ) ) (\mathrm{init}_{\mathrm{tid}}(e),\mathrm{src}(\mu(e))) ( init tid ( e ) , src ( μ ( e ))) if e e e has no incoming s b \mathrm{sb} sb -edge. By Item (3), this is the case if c ∈ Q s r c c\in Q_{\mathrm{src}} c ∈ Q src . Then the second rule applies, and its premise is exactly this condition, as λ t r ( c ) = μ ( e ) \lambda_{\mathrm{tr}}(c)=\mu(e) λ tr ( c ) = μ ( e ) by Item (2), and t i d ( l a b ( μ ( e ) ) ) = t i d ( e ) \mathrm{tid}(\mathrm{lab}(\mu(e)))=\mathrm{tid}(e) tid ( lab ( μ ( e ))) = tid ( e ) by Item (1). Items (1) and (4) are unaffected.
I n t r o b ( c 1 , c 2 ) \mathrm{Intro}_{b}(c_{1},c_{2}) Intro b ( c 1 , c 2 ) with b ∈ { r f , m b } b\in\{\mathrm{rf},\mathrm{mb}\} b ∈ { rf , mb } . The state, μ \mu μ , the coloring and s b \mathrm{sb} sb are unchanged, so all five claims carry over. □ \square □
We now use this invariant to prove that A p k \mathcal{A}^{k}_{\mathrm{p}} A p k is correct.
Lemma 5.2. For every k ∈ N k \in\mathbb{N} k ∈ N and concurrent program P P P , there exists a word automaton A p k \mathcal{A}^{k}_{\mathrm{p}} A p k with O ( ∣ P ∣ k + 1 ) 2 O ( k ) O(|P|^{k+1})\,2^{O(k)} O ( ∣ P ∣ k + 1 ) 2 O ( k ) states such that, for every w ∈ L ( A w f k ) w \in L(\mathcal{A}^{k}_{\mathrm{wf}}) w ∈ L ( A wf k ) , A p k \mathcal{A}^{k}_{\mathrm{p}} A p k accepts w w w iff ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^{w}.E,G^{w}.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Proof. A state is a pair of a subset of [ k + 1 ] [k+1] [ k + 1 ] and a partial map [ k + 1 ] ⇀ ⋃ t Δ t [k+1] \rightharpoonup\bigcup_{t}\Delta_{t} [ k + 1 ] ⇀ ⋃ t Δ t . By § 2.3 , ∣ ⋃ t Δ t ∣ ≤ ∣ P ∣ |\bigcup_{t}\Delta_{t}| \leq|P| ∣ ⋃ t Δ t ∣ ≤ ∣ P ∣ , so there are at most 2 k + 1 ⋅ ( ∣ P ∣ + 1 ) k + 1 ≤ 2 k + 1 ⋅ ( 2 ∣ P ∣ ) k + 1 = O ( ∣ P ∣ k + 1 ) 2 O ( k ) 2^{k+1}\cdot(|P|+1)^{k+1} \leq2^{k+1}\cdot(2|P|)^{k+1}=O(|P|^{k+1})\,2^{O(k)} 2 k + 1 ⋅ ( ∣ P ∣ + 1 ) k + 1 ≤ 2 k + 1 ⋅ ( 2∣ P ∣ ) k + 1 = O ( ∣ P ∣ k + 1 ) 2 O ( k ) states. Let w w w be closed, with G w G^{w} G w an execution graph. Since G w . s b G^{w}.\mathrm{sb} G w . sb is well-formed, for each t ∈ T i d t \in\mathrm{Tid} t ∈ Tid the events of E t E^{t} E t form a single sb-path e 1 ⟶ s b ⋯ ⟶ s b e n e_{1}\mathrel{\mathop{\longrightarrow}\limits^{\mathrm{sb}}}\cdots\mathrel{\mathop{\longrightarrow}\limits^{\mathrm{sb}}}e_{n} e 1 ⟶ sb ⋯ ⟶ sb e n , and G w . s b t = lab ( e 1 ) ⋯ lab ( e n ) G^{w}.{\mathrm{sb}}^{t}=\operatorname{lab}(e_{1})\cdots\operatorname{lab}(e_{n}) G w . sb t = lab ( e 1 ) ⋯ lab ( e n ) .
Soundness. Suppose a run ρ \rho ρ of A p k \mathcal{A}^{k}_{\mathrm{p}} A p k accepts w w w , and fix t t t with E t E^{t} E t as above. If n = 0 n=0 n = 0 , the empty run of P s e q t \mathrm{Pseq}_{t} Pseq t emits the empty word, so assume n ≥ 1 n\geq1 n ≥ 1 . Since w w w is closed, every event is uncolored at the end of w w w , and e 1 e_{1} e 1 has no incoming sb-edge, so Item (5) gives ϵ \epsilon ϵ -reach( i n i t t , src ( μ ( e 1 ) ) ) (\mathrm{init}_{t},\operatorname{src}(\mu(e_{1}))) ( init t , src ( μ ( e 1 ))) . Item (4) gives ϵ \epsilon ϵ -reach( tgt ( μ ( e i ) ) , src ( μ ( e i + 1 ) ) ) (\operatorname{tgt}(\mu(e_{i})),\operatorname{src}(\mu(e_{i+1}))) ( tgt ( μ ( e i )) , src ( μ ( e i + 1 ))) for every i < n i<n i < n . Concatenating these ϵ \epsilon ϵ -paths with the transitions μ ( e 1 ) , … , μ ( e n ) \mu(e_{1}),\ldots,\mu(e_{n}) μ ( e 1 ) , … , μ ( e n ) yields a run of P s e q t \mathrm{Pseq}_{t} Pseq t from i n i t t \mathrm{init}_{t} init t . Its non-silent transitions are exactly μ ( e 1 ) , … , μ ( e n ) \mu(e_{1}),\ldots,\mu(e_{n}) μ ( e 1 ) , … , μ ( e n ) , whose labels are lab ( e 1 ) , … , lab ( e n ) \operatorname{lab}(e_{1}),\ldots,\operatorname{lab}(e_{n}) lab ( e 1 ) , … , lab ( e n ) by Item (1). Hence G w . s b t ∈ L ( P s e q t ) G^{w}.{\mathrm{sb}}^{t}\in L(\mathrm{Pseq}_{t}) G w . sb t ∈ L ( Pseq t ) for every t t t , i.e., ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^{w}.E,G^{w}.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Completeness. Suppose ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^{w}.E,G^{w}.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) , and fix t t t with E t E^{t} E t as above. Some run of P s e q t \mathrm{Pseq}_{t} Pseq t emits lab ( e 1 ) ⋯ lab ( e n ) \operatorname{lab}(e_{1})\cdots\operatorname{lab}(e_{n}) lab ( e 1 ) ⋯ lab ( e n ) ; let δ 1 , … , δ n \delta_{1},\ldots,\delta_{n} δ 1 , … , δ n be its non-silent transitions in order. Then δ i ∈ Δ t \delta_{i}\in\Delta_{t} δ i ∈ Δ t and lab ( δ i ) = lab ( e i ) \operatorname{lab}(\delta_{i})=\operatorname{lab}(e_{i}) lab ( δ i ) = lab ( e i ) , the silent transitions before δ 1 \delta_{1} δ 1 give ϵ \epsilon ϵ -reach( i n i t t , src ( δ 1 ) ) (\mathrm{init}_{t},\operatorname{src}(\delta_{1})) ( init t , src ( δ 1 )) , and those between δ i \delta_{i} δ i and δ i + 1 \delta_{i+1} δ i + 1 give ϵ \epsilon ϵ -reach( tgt ( δ i ) , src ( δ i + 1 ) ) (\operatorname{tgt}(\delta_{i}),\operatorname{src}(\delta_{i+1})) ( tgt ( δ i ) , src ( δ i + 1 )) . Let ρ \rho ρ be the run of A p k \mathcal{A}^{k}_{\mathrm{p}} A p k on w w w that chooses δ i \delta_{i} δ i at the operation introducing e i e_{i} e i , for every thread, so that μ ( e i ) = δ i \mu(e_{i})=\delta_{i} μ ( e i ) = δ i . We check that no premise fails along w w w , using Lemma E.6 for the prefix preceding each operation. The premises of Intro hold by the choice of δ i \delta_{i} δ i . The premise ϵ \epsilon ϵ -reach of I n t r o s b ( c 1 , c 2 ) \mathrm{Intro}_{\mathrm{sb}}(c_{1},c_{2}) Intro sb ( c 1 , c 2 ) holds because the edge is some e i ⟶ s b e i + 1 e_{i}\mathrel{\mathop{\longrightarrow}\limits^{\mathrm{sb}}}e_{i+1} e i ⟶ sb e i + 1 and λ t r ( c j ) = μ ( χ − 1 ( c j ) ) \lambda_{\mathrm{tr}}(c_{j})=\mu(\chi^{-1}(c_{j})) λ tr ( c j ) = μ ( χ − 1 ( c j )) by Item (2). Its premise c 2 ∈ Q s r c c_{2}\in Q_{\mathrm{src}} c 2 ∈ Q src holds by Item (3), as e i + 1 e_{i+1} e i + 1 has exactly one incoming sb-edge in G w G^{w} G w and each edge is introduced once. For the second Forget rule, c ∈ Q s r c c\in Q_{\mathrm{src}} c ∈ Q src means that χ − 1 ( c ) \chi^{-1}(c) χ − 1 ( c ) has no incoming sb-edge, and it takes none after being forgotten; hence it is e 1 e_{1} e 1 of its thread, and the premise holds because of ϵ \epsilon ϵ -reach( i n i t t , src ( δ 1 ) ) (\mathrm{init}_{t},\operatorname{src}(\delta_{1})) ( init t , src ( δ 1 )) . The remaining rules have no premise that can fail. Finally, w w w is closed, so λ t r = ∅ \lambda_{\mathrm{tr}}=\varnothing λ tr = ∅ by Item (2) and Q s r c ⊆ img ( χ ) = ∅ Q_{\mathrm{src}}\subseteq\operatorname{img}(\chi)=\varnothing Q src ⊆ img ( χ ) = ∅ by Item (3), and ρ \rho ρ ends in the accepting state ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ . □
Proofs of SUBSEC:AUTMM
In this subsection, we prove that A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k recognizes the graphs that are consistent in MM (Lemma 5.3), and derive its complement. Fix K M M = ⟨ Q , T e s t s ∪ R e l , Δ , i n i t , Q F ⟩ \mathcal{K}_{\mathrm{MM}}=\langle Q,\mathrm{Tests}\cup\mathrm{Rel},\Delta,\mathrm{init},Q_{F}\rangle K MM = ⟨ Q , Tests ∪ Rel , Δ , init , Q F ⟩ as in § 5.3 . Throughout, w w w is well-formed and G c w = ⟨ E , s b , r f , m b , χ ⟩ G^{w}_{c}=\langle E,\mathrm{sb},\mathrm{rf},\mathrm{mb},\chi\rangle G c w = ⟨ E , sb , rf , mb , χ ⟩ . We use the walks, their interiors, and the events e c e_{c} e c of § 5.3 . Note that walks compose. If a walk from e e e to e ′ e' e ′ leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q q q to q ′ q' q ′ , and a walk from e ′ e' e ′ to e ′ ′ e'' e ′′ leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q ′ q' q ′ to q ′ ′ q'' q ′′ , then together they form a walk from e e e to e ′ ′ e'' e ′′ that leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q q q to q ′ ′ q'' q ′′ .
Definition E.7. Let E ′ ⊆ E E'\subseteq E E ′ ⊆ E be a set of events. A tuple ⟨ c 1 , c 2 , q 1 , q 2 ⟩ \langle c_{1},c_{2},q_{1},q_{2}\rangle ⟨ c 1 , c 2 , q 1 , q 2 ⟩ with c 1 , c 2 ∈ IMG ( χ ) c_{1},c_{2}\in\operatorname{IMG}(\chi) c 1 , c 2 ∈ IMG ( χ ) (i) is a path summary over E ′ E' E ′ if some walk from e c 1 e_{c_{1}} e c 1 to e c 2 e_{c_{2}} e c 2 with interior in E ′ E' E ′ leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q 1 q_{1} q 1 to q 2 q_{2} q 2 ; and (ii) is a cycle summary over E ′ E' E ′ if, for some e ∈ E ′ e\in E' e ∈ E ′ , some walk from e e e to e c 1 e_{c_{1}} e c 1 with interior in E ′ E' E ′ leads K M M \mathcal{K}_{\mathrm{MM}} K MM from i n i t \mathrm{init} init to q 1 q_{1} q 1 , and some walk from e c 2 e_{c_{2}} e c 2 to e e e with interior in E ′ E' E ′ leads K M M \mathcal{K}_{\mathrm{MM}} K MM from q 2 q_{2} q 2 to a state of Q F Q_{F} Q F . We write Q p t h w Q^{w}_{\mathrm{pth}} Q pth w and Q c y c w Q^{w}_{\mathrm{cyc}} Q cyc w for the path and cycle summaries over the uncolored events of G c w G^{w}_{c} G c w .
Note that Q p t h w Q^{w}_{\mathrm{pth}} Q pth w and Q c y c w Q^{w}_{\mathrm{cyc}} Q cyc w are exactly the sets described in § 5.3 . We define summaries over an arbitrary set E ′ E' E ′ because T C ( c , ⋅ , ⋅ ) \mathrm{TC}(c,\cdot,\cdot) TC ( c , ⋅ , ⋅ ) lets walks pass through e c e_{c} e c , and so considers the uncolored events together with e c e_{c} e c . The following lemma shows that TC computes exactly the summaries over this larger set.
Lemma E.8. Let c ∈ img ( χ ) c \in\operatorname{img}(\chi) c ∈ img ( χ ) , let U U U be the set of uncolored events of G c w G_c^w G c w , and let ⟨ Q p t h ′ ′ , Q c y c ′ ′ ⟩ = tc ( c , Q p t h w , Q c y c w ) \langle Q''_{pth}, Q''_{cyc}\rangle= \operatorname{tc}(c,Q^w_{pth},Q^w_{cyc}) ⟨ Q pt h ′′ , Q cy c ′′ ⟩ = tc ( c , Q pt h w , Q cy c w ) . Then (i) Q p t h ′ ′ Q''_{pth} Q pt h ′′ is the set of path summaries over U ∪ { e c } U \cup\{e_c\} U ∪ { e c } , and (ii) Q c y c ′ ′ Q''_{cyc} Q cy c ′′ is the set of cycle summaries over U ∪ { e c } U \cup\{e_c\} U ∪ { e c } .
Proof. Let U ′ ≜ U ∪ { e c } U' \triangleq U \cup\{e_c\} U ′ ≜ U ∪ { e c } . We first show, by induction on the construction of the fixed points, that every tuple of Q p t h ′ ′ Q''_{pth} Q pt h ′′ and Q c y c ′ ′ Q''_{cyc} Q cy c ′′ is a summary over U ′ U' U ′ . The tuples of Q p t h w Q^w_{pth} Q pt h w and Q c y c w Q^w_{cyc} Q cy c w are summaries over U U U , and hence over U ′ U' U ′ . Rule (i) composes two walks at e c e_c e c , which is in U ′ U' U ′ . Rule (ii) takes the first half of a cycle summary, which ends at e c e_c e c , and extends it by a walk from e c e_c e c to e c 1 e_{c_1} e c 1 . The resulting walk still starts at the anchor e e e and has its interior in U ′ U' U ′ . Rule (iii) does the same for the second half. Finally, Rule (iv) uses e c ∈ U ′ e_c \in U' e c ∈ U ′ itself as the anchor.
Conversely, we show that every summary over U ′ U' U ′ is in Q p t h ′ ′ Q''_{pth} Q pt h ′′ , respectively Q c y c ′ ′ Q''_{cyc} Q cy c ′′ . For Item (i), consider a walk from e c 1 e_{c_1} e c 1 to e c 2 e_{c_2} e c 2 with interior in U ′ U' U ′ . We cut it at every occurrence of e c e_c e c in its interior. Each piece has its interior in U U U , so its summary is in Q p t h w ⊆ Q p t h ′ ′ Q^w_{pth} \subseteq Q''_{pth} Q pt h w ⊆ Q pt h ′′ . Rule (i) then puts the pieces back together.
For Item (ii), consider a cycle summary over U ′ U' U ′ with anchor e e e . Let π 1 \pi_1 π 1 be its first half, from e e e to e c 1 e_{c_1} e c 1 , and π 2 \pi_2 π 2 its second half, from e c 2 e_{c_2} e c 2 to e e e . If e = e c e=e_c e = e c , then π 1 \pi_1 π 1 and π 2 \pi_2 π 2 are walks with interior in U ′ U' U ′ that start and end at colored events. So, their summaries are in Q p t h ′ ′ Q''_{pth} Q pt h ′′ by Item (i), and Rule (iv) applies. Otherwise, e ∈ U e \in U e ∈ U . If π 1 \pi_1 π 1 visits e c e_c e c , we cut it at its first occurrence of e c e_c e c . This gives a walk from e e e to e c e_c e c with interior in U U U , followed by a walk from e c e_c e c to e c 1 e_{c_1} e c 1 with interior in U ′ U' U ′ . Symmetrically, if π 2 \pi_2 π 2 visits e c e_c e c , we cut it at its last occurrence of e c e_c e c . The two outer pieces share the anchor e ∈ U e \in U e ∈ U and have their interiors in U U U . Hence, they form a cycle summary over U U U , which is in Q c y c w ⊆ Q c y c ′ ′ Q^w_{cyc} \subseteq Q''_{cyc} Q cy c w ⊆ Q cy c ′′ . The inner pieces are path summaries over U ′ U' U ′ , so they are in Q p t h ′ ′ Q''_{pth} Q pt h ′′ by Item (i). Rules (ii) and (iii) then attach them to the cycle summary. □
The following lemma describes the state that A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k reaches after reading w w w .
Lemma E.9. Let w w w be well-formed and suppose A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k has a run on w w w , reaching ⟨ Q p t h , Q c y c ⟩ \langle Q_{pth}, Q_{cyc}\rangle ⟨ Q pt h , Q cy c ⟩ . Then Q p t h = Q p t h w Q_{pth}=Q^w_{pth} Q pt h = Q pt h w and Q c y c = Q c y c w Q_{cyc}=Q^w_{cyc} Q cy c = Q cy c w .
Proof. By induction on ∣ w ∣ |w| ∣ w ∣ . For the empty word, the state is ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ and G c e = ⊥ G_c^e=\bot G c e = ⊥ , so Q p t h e = Q c y c e = ∅ Q^e_{pth}=Q^e_{cyc}=\varnothing Q pt h e = Q cy c e = ∅ . For the inductive step, let op \operatorname{op} op be the last operation of w w w and w ′ w' w ′ the prefix before it, and assume that Q p t h = Q p t h w ′ Q_{pth}=Q^{w'}_{pth} Q pt h = Q pt h w ′ and Q c y c = Q c y c w ′ Q_{cyc}=Q^{w'}_{cyc} Q cy c = Q cy c w ′ .
Intro ( lab , c ) (\operatorname{lab},c) ( lab , c ) . The new event e c e_c e c has no edges. So, a walk that visits e c e_c e c never leaves it, and consists only of tests satisfied by lab \operatorname{lab} lab . If such a walk has two or more steps, then e c e_c e c is in its interior. As e c e_c e c is colored, this walk yields no path summary. Hence, the new path summaries come from walks from e c e_c e c to itself with empty interior. These are the empty walk, which gives ⟨ c , c , q , q ⟩ \langle c,c,q,q\rangle ⟨ c , c , q , q ⟩ , and the single tests τ \tau τ with lab ∈ τ \operatorname{lab}\in\tau lab ∈ τ , which give step ( c , τ , c ) \operatorname{step}(c,\tau,c) step ( c , τ , c ) . This is exactly what AddTests \operatorname{AddTests} AddTests adds. There are no new cycle summaries, since a half would need an edge to reach e c e_c e c from an uncolored event.
Intro ( c 1 , c 2 ) (c_1,c_2) ( c 1 , c 2 ) . The new edge joins two colored events. So, a walk with uncolored interior can only use it if the walk consists of this single step. Hence, the new path summaries come from the step b b b from e c 1 e_{c_1} e c 1 to e c 2 e_{c_2} e c 2 and the step b − 1 b^{-1} b − 1 back, which is exactly what AddEdges \operatorname{AddEdges} AddEdges adds. There are no new cycle summaries. This is because every event of a half other than its colored endpoint is uncolored, so a half never uses an edge between two colored events.
Forget ( c ) (c) ( c ) . The uncolored events of G c w G_c^w G c w are those of G c w ′ G_c^{w'} G c w ′ together with e c e_c e c . By Lemma E.8 , the function tc \operatorname{tc} tc of the rule Forget ( c ) \operatorname{Forget}(c) Forget ( c ) returns the path and cycle summaries over this set, respect to the colors of G c w ′ G^{w'}_c G c w ′ . The summaries with respect to the colors of G c w G^w_c G c w are those that do not mention c c c , and these are exactly the ones that erase keeps.
We now use this invariant to prove that A M M k A^k_{\mathrm{MM}} A MM k is correct.
Lemma 5.3. For every k ∈ N k \in\mathbb{N} k ∈ N and memory model M M \mathrm{MM} MM , there is a deterministic word automaton A M M k A^k_{\mathrm{MM}} A MM k with 2 O ( k 2 ⋅ ∣ M M ∣ 2 ) 2^{O(k^2\cdot|\mathrm{MM}|^2)} 2 O ( k 2 ⋅ ∣ MM ∣ 2 ) states such that, for every w ∈ L ( A W F k ) w \in\mathcal{L}(A^k_{\mathrm{WF}}) w ∈ L ( A WF k ) , A M M k A^k_{\mathrm{MM}} A MM k accepts w w w iff G w ⊨ M M G^w \models\mathrm{MM} G w ⊨ MM . Complementing A M M k A^k_{\mathrm{MM}} A MM k yields a deterministic word automaton A ¬ M M k A^k_{\neg\mathrm{MM}} A ¬ MM k with the same states that, for every w ∈ L ( A W F k ) w \in\mathcal{L}(A^k_{\mathrm{WF}}) w ∈ L ( A WF k ) , accepts w w w iff G w ⊭ M M G^w \not\models\mathrm{MM} G w ⊨ MM .
Proof. There are 2 ( k + 1 ) 2 ⋅ ∣ Q ∣ 2 2^{(k+1)^2\cdot|Q|^2} 2 ( k + 1 ) 2 ⋅ ∣ Q ∣ 2 values each for Q p t h Q_{pth} Q pt h and Q c y c Q_{cyc} Q cy c , and one additional sink state. As ∣ Q ∣ ≤ 2 ∣ M M ∣ + 2 |Q| \le2|\mathrm{MM}|+2 ∣ Q ∣ ≤ 2∣ MM ∣ + 2 , A M M k A^k_{\mathrm{MM}} A MM k has 2 O ( k 2 ⋅ ∣ M M ∣ 2 ) 2^{O(k^2\cdot|\mathrm{MM}|^2)} 2 O ( k 2 ⋅ ∣ MM ∣ 2 ) states.
It is deterministic by construction (§ 5.3 ). Let w w w be closed, with G w G^w G w an execution graph. For every prefix of w w w of the form w ′ F o r g e t ( c ) w'\ \mathrm{Forget}(c) w ′ Forget ( c ) , let ⟨ Q p t h ′ ′ , Q c y c ′ ′ ⟩ = t c ( c , Q p t h w ′ , Q c y c w ′ ) \langle Q''_{pth},Q''_{cyc}\rangle=\mathrm{tc}(c,Q^{w'}_{pth},Q^{w'}_{cyc}) ⟨ Q pt h ′′ , Q cy c ′′ ⟩ = tc ( c , Q pt h w ′ , Q cy c w ′ ) , and let U ′ U' U ′ be the set of uncolored events of G c w ′ G^{w'}_c G c w ′ together with e c e_c e c . If the run of A M M k A^k_{\mathrm{MM}} A MM k on w w w reaches the end of w ′ w' w ′ , then its state there is ⟨ Q p t h w ′ , Q c y c w ′ ⟩ \langle Q^{w'}_{pth},Q^{w'}_{cyc}\rangle ⟨ Q pt h w ′ , Q cy c w ′ ⟩ by Lemma E.9 . So, the F o r g e t ( c ) \mathrm{Forget}(c) Forget ( c ) rule computes exactly ⟨ Q p t h ′ , Q c y c ′ ⟩ \langle Q'_{pth},Q'_{cyc}\rangle ⟨ Q pt h ′ , Q cy c ′ ⟩ .
Soundness. Suppose that G w ⊭ M M G^w \not\models\mathrm{MM} G w ⊨ MM . We show that w w w is rejected. Consider a cyclic realization e 0 , … , e m e_0,\ldots,e_m e 0 , … , e m , with e 0 = e m e_0=e_m e 0 = e m , of a word on which K M M K_{\mathrm{MM}} K MM has a run q 0 , … , q m q_0,\ldots,q_m q 0 , … , q m with q 0 = i n i t q_0=\mathrm{init} q 0 = init and q m ∈ Q F q_m \in Q_F q m ∈ Q F . As w w w is closed, every event of the realization is forgotten at some point of w w w . Let F o r g e t ( c ) \mathrm{Forget}(c) Forget ( c ) be the operation that forgets the last of them, and w ′ w' w ′ the prefix before it. Then every event of the realization is in U ′ U' U ′ . Moreover, edges are only drawn between colored events, so no edge between two events of U ′ U' U ′ is drawn after w ′ F o r g e t ( c ) w'\ \mathrm{Forget}(c) w ′ Forget ( c ) . Hence, the realization already lies in G w ′ G^{w'} G w ′ . If e 0 = e c e_0=e_c e 0 = e c , the realization is a walk from e c e_c e c to itself with interior in U ′ U' U ′ . So, ⟨ c , c , q 0 , q m ⟩ ∈ Q p t h ′ \langle c,c,q_0,q_m\rangle\in Q'_{pth} ⟨ c , c , q 0 , q m ⟩ ∈ Q pt h ′ by Lemma E.8 . The empty walk at e c e_c e c also gives ⟨ c , c , q 0 , q 0 ⟩ ∈ Q p t h ′ \langle c,c,q_0,q_0\rangle\in Q'_{pth} ⟨ c , c , q 0 , q 0 ⟩ ∈ Q pt h ′ , and Rule (iv) yields ⟨ c , c , q 0 , q 0 ⟩ ∈ Q c y c ′ \langle c,c,q_0,q_0\rangle\in Q'_{cyc} ⟨ c , c , q 0 , q 0 ⟩ ∈ Q cy c ′ . Otherwise, let j j j be the first index with e j = e c e_j=e_c e j = e c . Then e 0 , … , e j e_0,\ldots,e_j e 0 , … , e j and e j , … , e m e_j,\ldots,e_m e j , … , e m are the two halves of a cycle summary over U ′ U' U ′ with anchor e 0 e_0 e 0 . So, ⟨ c , c , q j , q j ⟩ ∈ Q c y c ′ \langle c,c,q_j,q_j\rangle\in Q'_{cyc} ⟨ c , c , q j , q j ⟩ ∈ Q cy c ′ by Lemma E.8 . In both cases, v i o l a t i o n F r e e ( Q c y c ′ ) \mathrm{violationFree}(Q'_{cyc}) violationFree ( Q cy c ′ ) fails at this F o r g e t \mathrm{Forget} Forget . Since A M M k A^k_{\mathrm{MM}} A MM k is deterministic, its only run on w w w enters the sink at this point, if it has not done so already. Hence, w w w is rejected.
Completeness. Conversely, suppose that G w ⊨ M M G^w \models\mathrm{MM} G w ⊨ MM . We first show that no F o r g e t \mathrm{Forget} Forget along w w w detects a violation. Assume, for contradiction, that ⟨ c , c ′ , q , q ⟩ ∈ Q c y c ′ ′ \langle c,c',q,q\rangle\in Q''_{cyc} ⟨ c , c ′ , q , q ⟩ ∈ Q cy c ′′ at some prefix w ′ F o r g e t ( c ) w'\ \mathrm{Forget}(c) w ′ Forget ( c ) . By Lemma E.8 , this tuple is a cycle summary over U ′ U' U ′ . In other words, some anchor e e e has a walk to e c ′ e_{c'} e c ′ that leads K M M K_{\mathrm{MM}} K MM from init to q q q , and e c ′ e_{c'} e c ′ has a walk back to the anchor that leads K M M K_{\mathrm{MM}} K MM from q q q to some q F ∈ Q F q_F \in Q_F q F ∈ Q F . Together, these two walks form a cyclic realization in G w ′ G^{w'} G w ′ of a word on which K M M K_{\mathrm{MM}} K MM has a run from init to q F q_F q F . This word is accepted by K M M K_{\mathrm{MM}} K MM . Moreover, operations only add events and edges, so the realization is also a realization in G w G^w G w . This contradicts G w ⊨ M M G^w \models\mathrm{MM} G w ⊨ MM . So, the run on w w w never enters the sink. Again by Lemma E.9 , it ends in ⟨ Q p t h w , Q c y c w ⟩ \langle Q^w_{pth},Q^w_{cyc}\rangle ⟨ Q pt h w , Q cy c w ⟩ . As w w w is closed and summaries only mention active colors, this state is ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ , which is accepting.
Complement. Finally, let A ¬ M M k A^k_{\neg\mathrm{MM}} A ¬ MM k be the complement of A M M k A^k_{\mathrm{MM}} A MM k , which is deterministic and has the same states. For w ∈ L ( A W F k ) w \in\mathcal{L}(A^k_{\mathrm{WF}}) w ∈ L ( A WF k ) , A ¬ M M k A^k_{\neg\mathrm{MM}} A ¬ MM k accepts w w w iff A M M k A^k_{\mathrm{MM}} A MM k rejects it, iff G w ⊭ M M G^w \not\models\mathrm{MM} G w ⊨ MM by the above. □
Proofs of SUBSEC:AUTROB
In this subsection, we prove the results of Section 5.4. We first define the product automaton A R O B k A^k_{\mathrm{ROB}} A ROB k formally. We then consider programs that are given explicitly, i.e., as an LTS per thread, for which we can build A R O B k A^k_{\mathrm{ROB}} A ROB k and test it for emptiness. Finally, we prove that robustness is in PSPACE for programs given as code.
The product. We state the product for two arbitrary memory models M M 1 \mathrm{MM}_1 MM 1 and M M 2 \mathrm{MM}_2 MM 2 , as robustness against M M \mathrm{MM} MM is the case M M 1 = M M \mathrm{MM}_1=\mathrm{MM} MM 1 = MM and M M 2 = S C \mathrm{MM}_2=\mathrm{SC} MM 2 = SC .
Lemma E.10. Given k ∈ N k \in\mathbb{N} k ∈ N , a concurrent program P P P and two memory models M M 1 \mathrm{MM}_1 MM 1 and M M 2 \mathrm{MM}_2 MM 2 , there exists a word automaton A R O B k A_{\mathrm{ROB}}^{k} A ROB k with O ( ∣ P ∣ k + 1 ) ⋅ 2 O ( k 2 ⋅ ( ∣ M M 1 ∣ 2 + ∣ M M 2 ∣ 2 ) + k log ∣ L a b ∣ + ∣ T i d ∣ + ∣ L o c ∣ ) O(|P|^{k+1}) \cdot2^{O(k^2 \cdot(|\mathrm{MM}_1|^2+|\mathrm{MM}_2|^2) + k \log|\mathrm{Lab}| + |\mathrm{Tid}| + |\mathrm{Loc}|)} O ( ∣ P ∣ k + 1 ) ⋅ 2 O ( k 2 ⋅ ( ∣ MM 1 ∣ 2 + ∣ MM 2 ∣ 2 ) + k l o g ∣ Lab ∣ + ∣ Tid ∣ + ∣ Loc ∣ ) states that accepts w ∈ O p s ( k + 1 ) ∗ w \in\mathrm{Ops}(k+1)^* w ∈ Ops ( k + 1 ) ∗ iff w w w is closed, G w ∈ ⟦ P ⟧ M M 1 G^w \in\llbracket P \rrbracket_{\mathrm{MM}_1} G w ∈ [ [ P ] ] MM 1 , and G w ∉ ⟦ P ⟧ M M 2 G^w \notin\llbracket P \rrbracket_{\mathrm{MM}_2} G w ∈ / [ [ P ] ] MM 2 .
Proof. Let A R O B k A_{\mathrm{ROB}}^{k} A ROB k be the product of A W F k A_{\mathrm{WF}}^{k} A WF k , A P k A_{\mathrm{P}}^{k} A P k , A M M 1 k A_{\mathrm{MM}_1}^{k} A MM 1 k and A ¬ M M 2 k A_{\neg\mathrm{MM}_2}^{k} A ¬ MM 2 k . Its number of states is the product of the bounds of Lemmas 5.1 to 5.3, where 2 O ( k ) 2^{O(k)} 2 O ( k ) and 2 O ( k log k ) 2^{O(k\log k)} 2 O ( k l o g k ) are absorbed by 2 O ( k 2 ⋅ ( ∣ M M 1 ∣ 2 + ∣ M M 2 ∣ 2 ) ) 2^{O(k^2 \cdot(|\mathrm{MM}_1|^2+|\mathrm{MM}_2|^2))} 2 O ( k 2 ⋅ ( ∣ MM 1 ∣ 2 + ∣ MM 2 ∣ 2 )) . By Lemma 5.1, A W F k A_{\mathrm{WF}}^{k} A WF k accepts w w w iff w w w is closed and G w G^w G w is an execution graph. For such w w w , Lemma 5.2 gives that A P k A_{\mathrm{P}}^{k} A P k accepts w w w iff ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^w.E,G^w.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) , Lemma 5.3 that A M M 1 k A_{\mathrm{MM}_1}^{k} A MM 1 k accepts w w w iff G w ⊨ M M 1 G^w \models\mathrm{MM}_1 G w ⊨ MM 1 , and that A ¬ M M 2 k A_{\neg\mathrm{MM}_2}^{k} A ¬ MM 2 k accepts w w w iff G w ⊭ M M 2 G^w \not\models\mathrm{MM}_2 G w ⊨ MM 2 . Hence A R O B k A_{\mathrm{ROB}}^{k} A ROB k accepts w w w iff w w w is closed, G w ∈ ⟦ P ⟧ M M 1 G^w \in\llbracket P \rrbracket_{\mathrm{MM}_1} G w ∈ [ [ P ] ] MM 1 , and G w ∉ ⟦ P ⟧ M M 2 G^w \notin\llbracket P \rrbracket_{\mathrm{MM}_2} G w ∈ / [ [ P ] ] MM 2 , as the last holds for a graph of P P P iff G w ⊭ M M 2 G^w \not\models\mathrm{MM}_2 G w ⊨ MM 2 . □
Explicit programs. When the programs P s e q τ P_{\mathrm{seq}_\tau} P seq τ are given explicitly, we can simply build A R O B k A_{\mathrm{ROB}}^{k} A ROB k and test it for emptiness. This decides the existence of a witness of bounded pathwidth.
Lemma E.11. Given k ∈ N k \in\mathbb{N} k ∈ N , a concurrent program P P P , and two memory models M M 1 \mathrm{MM}_1 MM 1 and M M 2 \mathrm{MM}_2 MM 2 , whether there exists an execution graph G G G such that pw ( G ) ≤ k \operatorname{pw}(G) \leq k pw ( G ) ≤ k , G ∈ ⟦ P ⟧ M M 1 G \in\llbracket P \rrbracket_{\mathrm{MM}_1} G ∈ [ [ P ] ] MM 1 , and G ∉ ⟦ P ⟧ M M 2 G \notin\llbracket P \rrbracket_{\mathrm{MM}_2} G ∈ / [ [ P ] ] MM 2 is decidable in time ∣ P ∣ O ( k ) ⋅ 2 O ( k 2 ⋅ ( ∣ M M 1 ∣ 2 + ∣ M M 2 ∣ 2 ) + k log ∣ L a b ∣ + ∣ T i d ∣ + ∣ L o c ∣ ) |P|^{O(k)} \cdot2^{O(k^2 \cdot(|\mathrm{MM}_1|^2+|\mathrm{MM}_2|^2) + k\log|\mathrm{Lab}| + |\mathrm{Tid}| + |\mathrm{Loc}|)} ∣ P ∣ O ( k ) ⋅ 2 O ( k 2 ⋅ ( ∣ MM 1 ∣ 2 + ∣ MM 2 ∣ 2 ) + k l o g ∣ Lab ∣ + ∣ Tid ∣ + ∣ Loc ∣ ) .
Proof. Let A R O B k A_{\mathrm{ROB}}^{k} A ROB k be the automaton of Lemma E.10. If A R O B k A_{\mathrm{ROB}}^{k} A ROB k accepts some w w w , then G w ∈ ⟦ P ⟧ M M 1 ∖ ⟦ P ⟧ M M 2 G^w \in\llbracket P \rrbracket_{\mathrm{MM}_1} \setminus\llbracket P \rrbracket_{\mathrm{MM}_2} G w ∈ [ [ P ] ] MM 1 ∖ [ [ P ] ] MM 2 , and pw ( G w ) ≤ k \operatorname{pw}(G^w) \leq k pw ( G w ) ≤ k by Lemma 4.1. Conversely, if G ∈ ⟦ P ⟧ M M 1 ∖ ⟦ P ⟧ M M 2 G \in\llbracket P \rrbracket_{\mathrm{MM}_1} \setminus\llbracket P \rrbracket_{\mathrm{MM}_2} G ∈ [ [ P ] ] MM 1 ∖ [ [ P ] ] MM 2 has pw ( G ) ≤ k \operatorname{pw}(G) \leq k pw ( G ) ≤ k , then G = G w G=G^w G = G w for some closed w ∈ O p s ( k + 1 ) ∗ w \in\mathrm{Ops}(k+1)^* w ∈ Ops ( k + 1 ) ∗ by Lemma 4.1, and A R O B k A_{\mathrm{ROB}}^{k} A ROB k accepts w w w , as both sets of graphs are closed under the renaming of identifiers of § 2.2 . So it suffices to decide whether L ( A R O B k ) = ∅ \mathcal{L}(A_{\mathrm{ROB}}^{k})=\varnothing L ( A ROB k ) = ∅ . This takes time linear in the number of states and transitions of A R O B k A_{\mathrm{ROB}}^{k} A ROB k . Let n n n be the number of states given by Lemma E.10. The only nondeterministic component of A R O B k A_{\mathrm{ROB}}^{k} A ROB k is A P k A_{\mathrm{P}}^{k} A P k , whose Intro rule chooses one transition of P P P , so each state has at most ∣ O p s ( k + 1 ) ∣ ⋅ ∣ P ∣ |\mathrm{Ops}(k+1)|\cdot|P| ∣ Ops ( k + 1 ) ∣ ⋅ ∣ P ∣ outgoing transitions. With ∣ O p s ( k + 1 ) ∣ = O ( k ⋅ ∣ L a b ∣ + k 2 ) |\mathrm{Ops}(k+1)|=O(k\cdot|\mathrm{Lab}|+k^2) ∣ Ops ( k + 1 ) ∣ = O ( k ⋅ ∣ Lab ∣ + k 2 ) from § 4.2 , the time is n ⋅ ∣ O p s ( k + 1 ) ∣ ⋅ ∣ P ∣ n\cdot|\mathrm{Ops}(k+1)|\cdot|P| n ⋅ ∣ Ops ( k + 1 ) ∣ ⋅ ∣ P ∣ , which is within the stated bound. □
By definition (§ 3.2 ), if M M \mathrm{MM} MM admits ℓ \ell ℓ -pw-bounded witnesses, then P P P is not robust against M M \mathrm{MM} MM iff some G ∈ ⟦ P ⟧ M M ∖ ⟦ P ⟧ S C G \in\llbracket P \rrbracket_{\mathrm{MM}} \setminus\llbracket P \rrbracket_{\mathrm{SC}} G ∈ [ [ P ] ] MM ∖ [ [ P ] ] SC has pw ( G ) ≤ ℓ \operatorname{pw}(G) \leq\ell pw ( G ) ≤ ℓ . In other words, deciding robustness is the special case of Lemma E.11 with M M 1 = M M \mathrm{MM}_1=\mathrm{MM} MM 1 = MM , M M 2 = S C \mathrm{MM}_2=\mathrm{SC} MM 2 = SC and k = ℓ k=\ell k = ℓ .
Theorem E.12. Let M M \mathrm{MM} MM be a memory model that admits ℓ \ell ℓ -pw-bounded witnesses. Robustness of a concurrent program P P P against M M \mathrm{MM} MM is decidable in time ∣ P ∣ O ( ℓ ) ⋅ 2 O ( ℓ 2 ⋅ ∣ M M ∣ 2 + ℓ log ∣ L a b ∣ + ∣ T i d ∣ + ∣ L o c ∣ ) |P|^{O(\ell)} \cdot2^{O(\ell^2\cdot|\mathrm{MM}|^2+\ell\log|\mathrm{Lab}|+|\mathrm{Tid}|+|\mathrm{Loc}|)} ∣ P ∣ O ( ℓ ) ⋅ 2 O ( ℓ 2 ⋅ ∣ MM ∣ 2 + ℓ l o g ∣ Lab ∣ + ∣ Tid ∣ + ∣ Loc ∣ ) .
Proof. If P P P is not robust against M M \mathrm{MM} MM , then, as M M \mathrm{MM} MM admits ℓ \ell ℓ -pw-bounded witnesses, some G ∈ ⟦ P ⟧ M M ∖ ⟦ P ⟧ S C G \in\llbracket P \rrbracket_{\mathrm{MM}} \setminus\llbracket P \rrbracket_{\mathrm{SC}} G ∈ [ [ P ] ] MM ∖ [ [ P ] ] SC has pw ( G ) ≤ ℓ \operatorname{pw}(G) \leq\ell pw ( G ) ≤ ℓ . Conversely, any such G G G shows that ⟦ P ⟧ S C ≠ ⟦ P ⟧ M M \llbracket P \rrbracket_{\mathrm{SC}} \neq\llbracket P \rrbracket_{\mathrm{MM}} [ [ P ] ] SC = [ [ P ] ] MM . Hence P P P is robust against M M \mathrm{MM} MM iff the instance of Lemma E.11 with k = ℓ k=\ell k = ℓ , M M 1 = M M \mathrm{MM}_1=\mathrm{MM} MM 1 = MM and M M 2 = S C \mathrm{MM}_2=\mathrm{SC} MM 2 = SC has a negative answer. As ∣ S C ∣ |\mathrm{SC}| ∣ SC ∣ is a constant, the bound of Lemma E.11 becomes the one stated. □
Note that, for a fixed memory model and fixed domains, ℓ \ell ℓ is a constant. So, for explicit programs, robustness is decidable in time polynomial in ∣ P ∣ |P| ∣ P ∣ . Moreover, since prefix-closed memory models admit witnesses of pathwidth at most pw S C + 1 \operatorname{pw}_{\mathrm{SC}}+1 pw SC + 1 , we have the following corollary.
Corollary E.13. Robustness of a concurrent program P P P against a prefix-closed memory model M M \mathrm{MM} MM is decidable in time ∣ P ∣ O ( ∣ T i d ∣ + ∣ L o c ∣ ) ⋅ 2 O ( ( ∣ T i d ∣ + ∣ L o c ∣ ) 2 ⋅ ∣ M M ∣ 2 + ( ∣ T i d ∣ + ∣ L o c ∣ ) log ∣ L a b ∣ ) |P|^{O(|\mathrm{Tid}|+|\mathrm{Loc}|)} \cdot2^{O((|\mathrm{Tid}|+|\mathrm{Loc}|)^2\cdot|\mathrm{MM}|^2+(|\mathrm{Tid}|+|\mathrm{Loc}|)\log|\mathrm{Lab}|)} ∣ P ∣ O ( ∣ Tid ∣ + ∣ Loc ∣ ) ⋅ 2 O (( ∣ Tid ∣ + ∣ Loc ∣ ) 2 ⋅ ∣ MM ∣ 2 + ( ∣ Tid ∣ + ∣ Loc ∣ ) l o g ∣ Lab ∣ ) .
Proof. By Lemma 3.3, M M MM M M admits ℓ \ell ℓ -pw-bounded witnesses for ℓ = p w S C + 1 = ∣ T i d ∣ + ∣ L o c ∣ + 1 \ell= \mathrm{pw}_{\mathrm{SC}} + 1 = |\mathrm{Tid}| + |\mathrm{Loc}| + 1 ℓ = pw SC + 1 = ∣ Tid ∣ + ∣ Loc ∣ + 1 . Substituting this ℓ \ell ℓ in Theorem E.12 , the term ∣ T i d ∣ + ∣ L o c ∣ |\mathrm{Tid}| + |\mathrm{Loc}| ∣ Tid ∣ + ∣ Loc ∣ of the exponent is absorbed by ℓ log ∣ L a b ∣ \ell\log|\mathrm{Lab}| ℓ log ∣ Lab ∣ . □
Polynomial space. We finally prove Theorem 5.4. Throughout, N N N is the size of the input as in § 5.4 , and k k k is polynomial in N N N . A state ⟨ p c , ϕ ⟩ \langle pc,\phi\rangle ⟨ p c , ϕ ⟩ of P s e q t \mathrm{Pseq}_{t} Pseq t is encoded in O ( log n t + ∣ R e g t ∣ log ( ∣ V a l ∣ + 1 ) ) O(\log n_{t} + |\mathrm{Reg}_{t}|\log(|\mathrm{Val}| + 1)) O ( log n t + ∣ Reg t ∣ log ( ∣ Val ∣ + 1 )) bits, and a transition, as two states and a label, in poly ( N ) \operatorname{poly}(N) poly ( N ) bits.
The procedure of Theorem 5.4 relies on the following properties of the components of A K O B k \mathcal{A}^{k}_{\mathrm{KOB}} A KOB k .
Lemma E.14. The following hold.
Every state of A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k , A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k , A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k , A P k \mathcal{A}^{k}_{\mathrm{P}} A P k and A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k can be encoded using poly ( N ) \operatorname{poly}(N) poly ( N ) bits, and membership in the respective accepting set is decidable in polynomial time.
The alphabet O p s ( k + 1 ) \mathrm{Ops}(k + 1) Ops ( k + 1 ) has ( k + 1 ) ⋅ ∣ L a b ∣ + ( k + 1 ) + 3 ⋅ ( k + 1 ) 2 (k + 1)\cdot|\mathrm{Lab}| + (k + 1) + 3\cdot(k + 1)^{2} ( k + 1 ) ⋅ ∣ Lab ∣ + ( k + 1 ) + 3 ⋅ ( k + 1 ) 2 symbols, each encodable in O ( log N ) O(\log N) O ( log N ) bits, where ∣ L a b ∣ = O ( ∣ T i d ∣ ⋅ ∣ L o c ∣ ⋅ ∣ V a l ∣ 2 ⋅ ∣ A n n ∣ ) |\mathrm{Lab}| = O(|\mathrm{Tid}|\cdot|\mathrm{Loc}|\cdot|\mathrm{Val}|^{2}\cdot|\mathrm{Ann}|) ∣ Lab ∣ = O ( ∣ Tid ∣ ⋅ ∣ Loc ∣ ⋅ ∣ Val ∣ 2 ⋅ ∣ Ann ∣ ) is polynomial in N N N .
The automata A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k , A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k , A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k and A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k are deterministic: given a state q q q and an operation o p ∈ O p s ( k + 1 ) \mathrm{op}\in\mathrm{Ops}(k + 1) op ∈ Ops ( k + 1 ) , the successor of q q q under o p \mathrm{op} op is computable in polynomial time.
The automaton A P k \mathcal{A}^{k}_{\mathrm{P}} A P k has out-degree exponential in N N N ; nevertheless, given states q q q , q ′ q' q ′ and an operation o p ∈ O p s ( k + 1 ) \mathrm{op}\in\mathrm{Ops}(k + 1) op ∈ Ops ( k + 1 ) , whether q → o p q ′ q\xrightarrow{\mathrm{op}}q' q op q ′ is a transition of A P k \mathcal{A}^{k}_{\mathrm{P}} A P k is decidable in PSPACE.
Proof. For Item (1), note that a state ⟨ Q a c t , Q e d g ⟩ \langle Q_{\mathrm{act}},Q_{\mathrm{edg}}\rangle ⟨ Q act , Q edg ⟩ of A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k consists of a subset of [ k + 1 ] [k + 1] [ k + 1 ] and a subset of { s b , r f , m b } × [ k + 1 ] × [ k + 1 ] \{\mathrm{sb},\mathrm{rf},\mathrm{mb}\}\times[k + 1]\times[k + 1] { sb , rf , mb } × [ k + 1 ] × [ k + 1 ] , in ( k + 1 ) + 3 ( k + 1 ) 2 (k + 1) + 3(k + 1)^{2} ( k + 1 ) + 3 ( k + 1 ) 2 bits. A state ⟨ Q i n , Q o u t , Q f s t , Q l s t , λ r e p , λ t h r ⟩ \langle Q_{\mathrm{in}},Q_{\mathrm{out}},Q_{\mathrm{fst}},Q_{\mathrm{lst}},\lambda_{\mathrm{rep}},\lambda_{\mathrm{thr}}\rangle ⟨ Q in , Q out , Q fst , Q lst , λ rep , λ thr ⟩ of A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k takes 2 ( k + 1 ) 2(k + 1) 2 ( k + 1 ) bits for Q i n Q_{\mathrm{in}} Q in and Q o u t Q_{\mathrm{out}} Q out , 2 ∣ T i d ∣ 2|\mathrm{Tid}| 2∣ Tid ∣ bits for Q f s t Q_{\mathrm{fst}} Q fst and Q l s t Q_{\mathrm{lst}} Q lst , O ( k log k ) O(k\log k) O ( k log k ) bits for λ r e p \lambda_{\mathrm{rep}} λ rep , and O ( k log ( ∣ T i d ∣ + 1 ) ) O(k\log(|\mathrm{Tid}| + 1)) O ( k log ( ∣ Tid ∣ + 1 )) bits for λ t h r \lambda_{\mathrm{thr}} λ thr ; A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k is the same with L o c \mathrm{Loc} Loc and λ l o c \lambda_{\mathrm{loc}} λ loc in place of T i d \mathrm{Tid} Tid and λ t h r \lambda_{\mathrm{thr}} λ thr . A state of A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k stores a label and a bit per color, in O ( k log ∣ L a b ∣ ) O(k\log|\mathrm{Lab}|) O ( k log ∣ Lab ∣ ) bits. A state ⟨ Q s r c , λ t r ⟩ \langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle ⟨ Q src , λ tr ⟩ of A P k \mathcal{A}^{k}_{\mathrm{P}} A P k stores a subset of [ k + 1 ] [k + 1] [ k + 1 ] and a transition of some P s e q t \mathrm{Pseq}_{t} Pseq t per color, in ( k + 1 ) ⋅ poly ( N ) (k + 1)\cdot\operatorname{poly}(N) ( k + 1 ) ⋅ poly ( N ) bits. A state ⟨ Q p t h , Q c y c ⟩ \langle Q_{\mathrm{pth}},Q_{\mathrm{cyc}}\rangle ⟨ Q pth , Q cyc ⟩ of A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k is two subsets of [ k + 1 ] × [ k + 1 ] × Q × Q [k + 1]\times[k + 1]\times Q\times Q [ k + 1 ] × [ k + 1 ] × Q × Q , in 2 ( k + 1 ) 2 ∣ Q ∣ 2 2(k + 1)^{2}|Q|^{2} 2 ( k + 1 ) 2 ∣ Q ∣ 2 bits, where ∣ Q ∣ |Q| ∣ Q ∣ is polynomial in N N N by Lemma 2.1; the implicit sink takes one more bit. All of these are polynomial in N N N . Every accepting set is either the set of all states, as for A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , or described by emptiness of some components, as ⟨ ∅ , ∅ ⟩ \langle\varnothing,\varnothing\rangle ⟨ ∅ , ∅ ⟩ for A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k , or, for the complement A ¬ M M k \mathcal{A}^{k}_{\neg\mathrm{MM}} A ¬ MM k , by the negation of such a test, which is decidable in polynomial time.
For Item (2), the number of symbols is the count of § 4.2 . A label is a kind, a thread, at most one location, at most two values and an annotation, so ∣ L a b ∣ ≤ 4 ∣ T i d ∣ ⋅ ∣ L o c ∣ ⋅ ∣ V a l ∣ 2 ⋅ ∣ A n n ∣ |\mathrm{Lab}|\leq4|\mathrm{Tid}|\cdot|\mathrm{Loc}|\cdot|\mathrm{Val}|^{2}\cdot|\mathrm{Ann}| ∣ Lab ∣ ≤ 4∣ Tid ∣ ⋅ ∣ Loc ∣ ⋅ ∣ Val ∣ 2 ⋅ ∣ Ann ∣ . A symbol names an operation, at most two colors and at most one label, in O ( log k + log ∣ L a b ∣ ) = O ( log N ) O(\log k+\log|\mathrm{Lab}|)=O(\log N) O ( log k + log ∣ Lab ∣ ) = O ( log N ) bits.
For Item (3), the automata A F O R M k \mathcal{A}^{k}_{\mathrm{FORM}} A FORM k , A s b k \mathcal{A}^{k}_{\mathrm{sb}} A sb k , A r f k \mathcal{A}^{k}_{\mathrm{rf}} A rf k and A m b k \mathcal{A}^{k}_{\mathrm{mb}} A mb k are deterministic by Lemma 5.1 , and A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k by Lemma 5.3. Their rules evaluate MERGE and DROP, which scan at most k + 1 k + 1 k + 1 colors, compare labels, and, for A M M k \mathcal{A}^{k}_{\mathrm{MM}} A MM k , evaluate ADDTESTS, ADDEDGES, TC, VIOLATIONFREE and ERASE. The tests and transitions of K M M \mathcal{K}_{\mathrm{MM}} K MM are computed in polynomial time, so ADDTESTS and ADDEDGES take polynomial time. The sets T \mathcal{T} T are least fixed points over [ k + 1 ] × [ k + 1 ] × Q × Q [k + 1]\times[k + 1]\times Q\times Q [ k + 1 ] × [ k + 1 ] × Q × Q , computed by saturation in at most 2 ( k + 1 ) 2 ∣ Q ∣ 2 2(k + 1)^{2}|Q|^{2} 2 ( k + 1 ) 2 ∣ Q ∣ 2 rounds of polynomial time each.
For Item (4), note that a INTRO ( l a b , c ) \operatorname{INTRO}(\mathrm{lab},c) INTRO ( lab , c ) from ⟨ Q s r c , λ t r ⟩ \langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle ⟨ Q src , λ tr ⟩ may choose any transition δ \delta δ of P s e q t i d ( l a b ) \mathrm{Pseq}_{\mathrm{tid}(\mathrm{lab})} Pseq tid ( lab ) with l a b ( δ ) = l a b \mathrm{lab}(\delta)=\mathrm{lab} lab ( δ ) = lab , and there are exponentially many, one for each store; so the out-degree is exponential in N N N . Given q = ⟨ Q s r c , λ t r ⟩ q=\langle Q_{\mathrm{src}},\lambda_{\mathrm{tr}}\rangle q = ⟨ Q src , λ tr ⟩ , q ′ = ⟨ Q s r c ′ , λ t r ′ ⟩ q'=\langle Q'_{\mathrm{src}},\lambda'_{\mathrm{tr}}\rangle q ′ = ⟨ Q src ′ , λ tr ′ ⟩ and o p \mathrm{op} op , we check the rules of § 5.2 . Their premises are equalities between the components of q q q , q ′ q' q ′ and o p \mathrm{op} op , membership of δ \delta δ in Δ t i d ( l a b ) \Delta_{\mathrm{tid}(\mathrm{lab})} Δ tid ( lab ) , which takes polynomial time by the rules of the program semantics, and a premise ϵ - R E A C H ( u , v ) \epsilon\text{-}\mathrm{REACH}(u,v) ϵ - REACH ( u , v ) . The latter is reachability in the graph of silent transitions of P s e q t \mathrm{Pseq}_{t} Pseq t , whose vertices are encoded in polynomially many bits and whose edges are decidable in polynomial time. It is decidable in nondeterministic polynomial space by guessing a path one vertex at a time, with a counter up to the number 2 poly ( N ) 2^{\operatorname{poly}(N)} 2 poly ( N ) of vertices, and hence in PSPACE by Savitch’s theorem [11 ] . □
We can now prove Theorem 5.4.
Theorem 5.4. Let M M MM M M be a KAT-definable memory model that admits ℓ \ell ℓ -pw-bounded witnesses, for some ℓ \ell ℓ bounded by a polynomial in N N N . Given instruction sequences S t S_t S t for t ∈ T i d t \in\mathrm{Tid} t ∈ Tid and explicit domains T i d \mathrm{Tid} Tid , L o c \mathrm{Loc} Loc , R e g \mathrm{Reg} Reg , V a l \mathrm{Val} Val , A n n \mathrm{Ann} Ann , deciding whether the induced program P P P is robust against M M MM M M is in PSPACE.
Proof. Let A r o b ℓ \mathcal{A}^{\ell}_{\mathrm{rob}} A rob ℓ be the automaton of Lemma E.10 with M M 1 = M M \mathrm{MM}_1 = MM MM 1 = M M , M M 2 = S C \mathrm{MM}_2 = \mathrm{SC} MM 2 = SC and k = ℓ k = \ell k = ℓ , i.e., the product of A f o r m ℓ \mathcal{A}^{\ell}_{\mathrm{form}} A form ℓ , A s b ℓ \mathcal{A}^{\ell}_{\mathrm{sb}} A sb ℓ , A r f ℓ \mathcal{A}^{\ell}_{\mathrm{rf}} A rf ℓ , A m b ℓ \mathcal{A}^{\ell}_{\mathrm{mb}} A mb ℓ , A M M ℓ \mathcal{A}^{\ell}_{\mathrm{MM}} A MM ℓ and A ¬ S C ℓ \mathcal{A}^{\ell}_{\neg\mathrm{SC}} A ¬ SC ℓ . As in the proofs of Lemma E.11 and Theorem E.12 , P P P is not robust against M M MM M M iff L ( A r o b ℓ ) ≠ ∅ \mathcal{L}(\mathcal{A}^{\ell}_{\mathrm{rob}}) \ne\emptyset L ( A rob ℓ ) = ∅ ; these arguments do not depend on how P P P is given.
Let M M M be the number of states of A r o b ℓ \mathcal{A}^{\ell}_{\mathrm{rob}} A rob ℓ , which is 2 poly ( N ) 2^{\operatorname{poly}(N)} 2 poly ( N ) by Item (1) of Lemma E.14 with k = ℓ k = \ell k = ℓ . No component has an ϵ \epsilon ϵ -transition, so if L ( A r o b ℓ ) ≠ ∅ \mathcal{L}(\mathcal{A}^{\ell}_{\mathrm{rob}}) \ne\emptyset L ( A rob ℓ ) = ∅ , then a shortest accepted word has an accepting run that visits no state twice, and thus has length less than M M M . The following nondeterministic procedure decides L ( A r o b ℓ ) ≠ ∅ \mathcal{L}(\mathcal{A}^{\ell}_{\mathrm{rob}}) \ne\emptyset L ( A rob ℓ ) = ∅ . It stores the current state of each component, starting from the initial states, and a counter up to M M M . At each step, if every component is in an accepting state it accepts, and if the counter has reached M M M it rejects. Otherwise, it guesses o p ∈ O p s ( ℓ + 1 ) \mathrm{op} \in\mathrm{Ops}(\ell+ 1) op ∈ Ops ( ℓ + 1 ) , replaces the state of each deterministic component by its successor under o p \mathrm{op} op , guesses a state q ′ q' q ′ of A ρ ℓ \mathcal{A}^{\ell}_{\rho} A ρ ℓ and checks that q → o p q ′ q \xrightarrow{\mathrm{op}} q' q op q ′ is a transition from its current state q q q , rejecting if not, and increments the counter.
The sequence of states the procedure goes through on an accepting computation is an accepting run of A r o b ℓ \mathcal{A}^{\ell}_{\mathrm{rob}} A rob ℓ , and conversely every accepting run of length less than M M M is followed by some computation, so the procedure is correct. By Lemma E.14 , the states, the operation and the counter take polynomial space, the deterministic successors and the acceptance test take polynomial time, and the check of the transition of A ρ ℓ \mathcal{A}^{\ell}_{\rho} A ρ ℓ takes polynomial space, which is reused across steps. Hence non-robustness is in NPSPACE, which equals PSPACE by Savitch’s theorem [11 ] . As PSPACE is closed under complement, robustness is in PSPACE. □
Proofs of Section 6
Canonical Pathwidth
This subsection proves the results on canonical pathwidth of § 6 , starting with the canonical analogue of Lemma 4.1.
Lemma F.1. Let G G G be a free execution graph and k ≥ 0 k \ge0 k ≥ 0 . The following are equivalent. (i) G G G has a canonical path decomposition of width at most k k k . (ii) G = G w G = G^{w} G = G w for some canonical closed w ∈ O p s ( k + 1 ) ∗ w \in\mathrm{Ops}(k+1)^* w ∈ Ops ( k + 1 ) ∗ . Moreover, for a canonical closed w w w , the sequence DOM ( X w 0 ) , DOM ( X w 1 ) , … , DOM ( X w ∣ w ∣ ) \operatorname{DOM}(\mathcal{X}^{w_0}), \operatorname{DOM}(\mathcal{X}^{w_1}), \ldots, \operatorname{DOM}(\mathcal{X}^{w_{\lvert w\rvert}}) DOM ( X w 0 ) , DOM ( X w 1 ) , … , DOM ( X w ∣ w ∣ ) is a canonical path decomposition of G w G^{w} G w of width at most k k k .
Proof. For the moreover part, and hence (ii) ⇒ \Rightarrow ⇒ (i), the sequence is a path decomposition of width at most k k k by Lemma 4.1. The first bag containing an event is the one following its INTRO, so bags introduce events in the order of their INTROs in w w w , which follows sb as w w w is canonical.
For (i) ⇒ \Rightarrow ⇒ (ii), take a canonical path decomposition X 1 , … , X n \mathcal{X}_1, \ldots, \mathcal{X}_n X 1 , … , X n of width at most k k k , and write it as a word bag by bag. From X i \mathcal{X}_i X i to X i + 1 \mathcal{X}_{i+1} X i + 1 , first forget the events of X i ∖ X i + 1 \mathcal{X}_i \setminus\mathcal{X}_{i+1} X i ∖ X i + 1 , then introduce those of X i + 1 ∖ X i \mathcal{X}_{i+1} \setminus\mathcal{X}_i X i + 1 ∖ X i in an order extending sb, then draw every edge of G G G between events of X i + 1 \mathcal{X}_{i+1} X i + 1 that draw... yet; finally forget the events of X n X_n X n . Forgetting before introducing keeps at most k + 1 k+1 k + 1 events colored, so k + 1 k+1 k + 1 colors suffice, as in Lemma 4.1. Every edge is drawn, as its endpoints share a bag. Events are introduced in the order of their first bags, with ties ordered by sb, so the word is canonical, as the decomposition is.
Lemma 6.1. For every execution graph G G G , if G ⊨ S C G \models\mathrm{SC} G ⊨ SC then p w ( G ) ≤ c p w ( G ) ≤ p w S C \mathrm{pw}(G) \le\mathrm{cpw}(G) \le\mathrm{pw}_{\mathrm{SC}} pw ( G ) ≤ cpw ( G ) ≤ pw SC .
Proof. The decomposition in the proof of Lemma 3.2 has width at most p w S C \mathrm{pw}_{\mathrm{SC}} pw SC , and its first bag containing e i e_i e i is X i X_i X i . It introduces events in the order σ \sigma σ , which extends p o \mathrm{po} po , hence sb.
Lemma 6.2. Every prefix-closed memory model admits ( p w S C + 3 ) (\mathrm{pw}_{\mathrm{SC}}+3) ( pw SC + 3 ) -cpw-bounded witnesses, and ( p w S C + 2 ) (\mathrm{pw}_{\mathrm{SC}}+2) ( pw SC + 2 ) -cpw-bounded witnesses if every RMW reads from its mb-predecessor.
Proof. Fix a prefix-closed MM and a program P that is not robust against MM, and let G be a witness with smallest ∣ G . E ∣ |G.E| ∣ G . E ∣ . As G ⊭ S C G \not\models\mathrm{SC} G ⊨ SC , G is non-empty, so by prefix-closedness some maximal event e e e of G satisfies G ′ ≜ G ∖ { e } ∈ ⟦ P ⟧ M M G' \triangleq G \setminus\{e\} \in\llbracket P\rrbracket_{\mathrm{MM}} G ′ ≜ G ∖ { e } ∈ [ [ P ] ] MM . As G ′ G' G ′ has fewer events than G, it is not a witness, so G ′ ⊨ S C G' \models\mathrm{SC} G ′ ⊨ SC .
As e e e is maximal, it has no sb-successor and no rf-successor in G. Hence the neighbours of e e e in G are among its sb-predecessor e 1 e_1 e 1 , its rf-source e 2 e_2 e 2 , its mb-predecessor e 3 e_3 e 3 and its mb-successor e 4 e_4 e 4 , whenever these exist. Every other edge of G is an edge of G ′ G' G ′ . This is immediate for sb and rf, and an mb-edge of G that avoids e has no event of G ′ G' G ′ between its endpoints in mo.
We now build a decomposition of G. Let X 1 , … , X n X_1,\ldots,X_n X 1 , … , X n be the decomposition of G ′ G' G ′ from the proof of Lemma 3.2. It is canonical of width at most p w S C \mathrm{pw}_{\mathrm{SC}} pw SC by Lemma 6.1 . The last event of a thread is retained by the first clause of that construction until X n X_n X n . As e e e has no sb-successor, e 1 e_1 e 1 is the last event of tid ( e ) \operatorname{tid}(e) tid ( e ) in G ′ G' G ′ , and it lies in every bag from its first one to X n X_n X n . For j ∈ { 2 , 3 , 4 } j \in\{2,3,4\} j ∈ { 2 , 3 , 4 } , add e j e_j e j to every bag after its last one, and append X n + 1 ≜ { e , e 1 , e 2 , e 3 , e 4 } X_{n+1} \triangleq\{e,e_1,e_2,e_3,e_4\} X n + 1 ≜ { e , e 1 , e 2 , e 3 , e 4 } , dropping the neighbours that do not exist. The result is a path decomposition of G. Every event lies in a contiguous range of bags, X n + 1 X_{n+1} X n + 1 covers the edges at e, and the other edges are covered as in G ′ G' G ′ . It is canonical, as e is introduced last and its only sb-neighbour e 1 e_1 e 1 is introduced before.
It remains to bound the width. Each X i X_i X i with i ≤ n i \le n i ≤ n gains at most ∣ { e 2 , e 3 , e 4 } ∣ |\{e_2,e_3,e_4\}| ∣ { e 2 , e 3 , e 4 } ∣ events. A read has only e 2 e_2 e 2 , a write only e 3 e_3 e 3 and e 4 e_4 e 4 , an RMW all three, and a fence none. So each X i X_i X i gains at most 3 events, and at most 2 under atomicity, where e 2 = e 3 e_2=e_3 e 2 = e 3 for an RMW as G ⊨ M M G \models\mathrm{MM} G ⊨ MM . Moreover ∣ X n + 1 ∣ ≤ 5 |X_{n+1}| \le5 ∣ X n + 1 ∣ ≤ 5 , and ∣ X n + 1 ∣ ≤ 4 |X_{n+1}| \le4 ∣ X n + 1 ∣ ≤ 4 under atomicity, while p w S C ≥ 2 \mathrm{pw}_{\mathrm{SC}} \ge2 pw SC ≥ 2 as Tid and Loc are non-empty. Hence c p w ( G ) ≤ p w S C + 3 \mathrm{cpw}(G) \le\mathrm{pw}_{\mathrm{SC}}+3 cpw ( G ) ≤ pw SC + 3 , and c p w ( G ) ≤ p w S C + 2 \mathrm{cpw}(G) \le\mathrm{pw}_{\mathrm{SC}}+2 cpw ( G ) ≤ pw SC + 2 under atomicity.
An Automaton That Executes the Program
Transition rules of A S k \mathcal{A}^{k}_{S} A S k . The first four rules execute instructions that emit no event. The following five execute instructions that emit an event, and thus introduce it. The last four handle Forget and the Introb _b b operations. As there, a rule applies only when the expression it evaluates are not ⊥ \bot ⊥ .
t ∈ T i d S t ( P C ( t ) ) = d : = exp P C ′ = P C [ t ↦ P C ( t ) + 1 ] Φ ′ = Φ [ d ↦ Φ ( exp ) ] ⟨ P C , Φ , Q p n d , γ ⟩ → ϵ ⟨ P C ′ , Φ ′ , Q p n d , γ ⟩ \frac{
\begin{gathered}
t \in\mathrm{Tid}\qquad S_t(\mathrm{PC}(t))=d:=\exp\\
\mathrm{PC}'=\mathrm{PC}[t\mapsto\mathrm{PC}(t)+1]\\
\Phi'=\Phi[d\mapsto\Phi(\exp)]
\end{gathered}
}{
\langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\epsilon}
\langle\mathrm{PC}',\Phi',Q_{\mathrm{pnd}},\gamma\rangle
} ⟨ PC , Φ , Q pnd , γ ⟩ ϵ ⟨ PC ′ , Φ ′ , Q pnd , γ ⟩ t ∈ Tid S t ( PC ( t )) = d := exp PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ Φ ( exp )]
t ∈ T i d S t ( P C ( t ) ) = d : = N D e t ( V a l ′ ) v ∈ V a l ′ P C ′ = P C [ t ↦ P C ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] ⟨ P C , Φ , Q p n d , γ ⟩ → ϵ ⟨ P C ′ , Φ ′ , Q p n d , γ ⟩ \frac{
\begin{gathered}
t \in\mathrm{Tid}\qquad S_t(\mathrm{PC}(t))=d:=\mathrm{NDet}(\mathrm{Val}')\\
v\in\mathrm{Val}'\qquad\mathrm{PC}'=\mathrm{PC}[t\mapsto\mathrm{PC}(t)+1]\\
\Phi'=\Phi[d\mapsto v]
\end{gathered}
}{
\langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\epsilon}
\langle\mathrm{PC}',\Phi',Q_{\mathrm{pnd}},\gamma\rangle
} ⟨ PC , Φ , Q pnd , γ ⟩ ϵ ⟨ PC ′ , Φ ′ , Q pnd , γ ⟩ t ∈ Tid S t ( PC ( t )) = d := NDet ( Val ′ ) v ∈ Val ′ PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ]
t ∈ T i d S t ( P C ( t ) ) = i f exp g o t o m Φ ( exp ) ≠ 0 P C ′ = P C [ t ↦ m ] ⟨ P C , Φ , Q p n d , γ ⟩ → ϵ ⟨ P C ′ , Φ , Q p n d , γ ⟩ \frac{
\begin{gathered}
t\in\mathrm{Tid}\qquad S_t(\mathrm{PC}(t))=\mathrm{if}\ \exp\ \mathrm{goto}\ m\\
\Phi(\exp)\ne0\qquad\mathrm{PC}'=\mathrm{PC}[t\mapsto m]
\end{gathered}
}{
\langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\epsilon}
\langle\mathrm{PC}',\Phi,Q_{\mathrm{pnd}},\gamma\rangle
} ⟨ PC , Φ , Q pnd , γ ⟩ ϵ ⟨ PC ′ , Φ , Q pnd , γ ⟩ t ∈ Tid S t ( PC ( t )) = if exp goto m Φ ( exp ) = 0 PC ′ = PC [ t ↦ m ]
t ∈ T i d S t ( P C ( t ) ) = i f exp g o t o m Φ ( exp ) = 0 P C ′ = P C [ t ↦ P C ( t ) + 1 ] ⟨ P C , Φ , Q p n d , γ ⟩ → ϵ ⟨ P C ′ , Φ , Q p n d , γ ⟩ \frac{
\begin{gathered}
t\in\mathrm{Tid}\qquad S_t(\mathrm{PC}(t))=\mathrm{if}\ \exp\ \mathrm{goto}\ m\\
\Phi(\exp)=0\qquad\mathrm{PC}'=\mathrm{PC}[t\mapsto\mathrm{PC}(t)+1]
\end{gathered}
}{
\langle\mathrm{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\epsilon}
\langle\mathrm{PC}',\Phi,Q_{\mathrm{pnd}},\gamma\rangle
} ⟨ PC , Φ , Q pnd , γ ⟩ ϵ ⟨ PC ′ , Φ , Q pnd , γ ⟩ t ∈ Tid S t ( PC ( t )) = if exp goto m Φ ( exp ) = 0 PC ′ = PC [ t ↦ PC ( t ) + 1 ]
op = Intro ( lab , c ) lab = w a ( t , x , Φ ( exp ) ) S t ( PC ( t ) ) = x : = a exp PC ′ = PC [ t ↦ PC ( t ) + 1 ] Q p n d ′ = pend ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC ′ , Φ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\quad\operatorname{lab}=w_a(t,x,\Phi(\operatorname{exp}))\quad S_t(\operatorname{PC}(t))=x:=_a\operatorname{exp}\\
&\operatorname{PC}'=\operatorname{PC}[t\mapsto\operatorname{PC}(t)+1]\quad Q'_{\mathrm{pnd}}=\operatorname{pend}(Q_{\mathrm{pnd}},\gamma,t,c)\quad\gamma'=\gamma[t\mapsto c]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC}',\Phi,Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Intro ( lab , c ) lab = w a ( t , x , Φ ( exp )) S t ( PC ( t )) = x : = a exp PC ′ = PC [ t ↦ PC ( t ) + 1 ] Q pnd ′ = pend ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC ′ , Φ , Q pnd ′ , γ ′ ⟩
op = Intro ( lab , c ) lab = r a ( t , x , v ) S t ( PC ( t ) ) = d : = a x PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] Q p n d ′ = pend ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC ′ , Φ ′ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\quad\operatorname{lab}=r_a(t,x,v)\quad S_t(\operatorname{PC}(t))=d:=_a x\\
&\operatorname{PC}'=\operatorname{PC}[t\mapsto\operatorname{PC}(t)+1]\quad\Phi'=\Phi[d\mapsto v]\quad Q'_{\mathrm{pnd}}=\operatorname{pend}(Q_{\mathrm{pnd}},\gamma,t,c)\quad\gamma'=\gamma[t\mapsto c]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC}',\Phi',Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Intro ( lab , c ) lab = r a ( t , x , v ) S t ( PC ( t )) = d : = a x PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] Q pnd ′ = pend ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC ′ , Φ ′ , Q pnd ′ , γ ′ ⟩
op = Intro ( lab , c ) lab = rmw a ( t , x , Φ ( exp R ) , Φ ( exp W ) ) S t ( PC ( t ) ) = d : = a CAS ( x , exp R , exp W ) PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ Φ ( exp R ) ] Q p n d ′ = pend ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC ′ , Φ ′ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\quad\operatorname{lab}=\operatorname{rmw}_a(t,x,\Phi(\operatorname{exp}_R),\Phi(\operatorname{exp}_W))\\
&S_t(\operatorname{PC}(t))=d:=_a\operatorname{CAS}(x,\operatorname{exp}_R,\operatorname{exp}_W)\quad\operatorname{PC}'=\operatorname{PC}[t\mapsto\operatorname{PC}(t)+1]\\
&\Phi'=\Phi[d\mapsto\Phi(\operatorname{exp}_R)]\quad Q'_{\mathrm{pnd}}=\operatorname{pend}(Q_{\mathrm{pnd}},\gamma,t,c)\quad\gamma'=\gamma[t\mapsto c]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC}',\Phi',Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Intro ( lab , c ) lab = rmw a ( t , x , Φ ( exp R ) , Φ ( exp W )) S t ( PC ( t )) = d : = a CAS ( x , exp R , exp W ) PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ Φ ( exp R )] Q pnd ′ = pend ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC ′ , Φ ′ , Q pnd ′ , γ ′ ⟩
op = Intro ( lab , c ) lab = r ‾ a ( t , x , v ) v ≠ Φ ( exp R ) S t ( PC ( t ) ) = d : = a CAS ( x , exp R , exp W ) PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] Q p n d ′ = pend ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC ′ , Φ ′ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\quad\operatorname{lab}=\overline{r}_a(t,x,v)\quad v\ne\Phi(\operatorname{exp}_R)\\
&S_t(\operatorname{PC}(t))=d:=_a\operatorname{CAS}(x,\operatorname{exp}_R,\operatorname{exp}_W)\quad\operatorname{PC}'=\operatorname{PC}[t\mapsto\operatorname{PC}(t)+1]\\
&\Phi'=\Phi[d\mapsto v]\quad Q'_{\mathrm{pnd}}=\operatorname{pend}(Q_{\mathrm{pnd}},\gamma,t,c)\quad\gamma'=\gamma[t\mapsto c]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC}',\Phi',Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Intro ( lab , c ) lab = r a ( t , x , v ) v = Φ ( exp R ) S t ( PC ( t )) = d : = a CAS ( x , exp R , exp W ) PC ′ = PC [ t ↦ PC ( t ) + 1 ] Φ ′ = Φ [ d ↦ v ] Q pnd ′ = pend ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC ′ , Φ ′ , Q pnd ′ , γ ′ ⟩
op = Intro ( lab , c ) lab = f a ( t ) S t ( PC ( t ) ) = fence a PC ′ = PC [ t ↦ PC ( t ) + 1 ] Q p n d ′ = pend ( Q p n d , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC ′ , Φ , Q p n d ′ , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}(\operatorname{lab},c)\quad\operatorname{lab}=f_a(t)\\
&S_t(\operatorname{PC}(t))=\operatorname{fence}_a\quad\operatorname{PC}'=\operatorname{PC}[t\mapsto\operatorname{PC}(t)+1]\\
&Q'_{\mathrm{pnd}}=\operatorname{pend}(Q_{\mathrm{pnd}},\gamma,t,c)\quad\gamma'=\gamma[t\mapsto c]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC}',\Phi,Q'_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Intro ( lab , c ) lab = f a ( t ) S t ( PC ( t )) = fence a PC ′ = PC [ t ↦ PC ( t ) + 1 ] Q pnd ′ = pend ( Q pnd , γ , t , c ) γ ′ = γ [ t ↦ c ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC ′ , Φ , Q pnd ′ , γ ′ ⟩
op = Forget ( c ) ∄ c ′ ∈ [ k + 1 ] . ⟨ c , c ′ ⟩ ∈ Q p n d ∨ ⟨ c ′ , c ⟩ ∈ Q p n d ∄ t ∈ Tid . γ ( t ) = c ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC , Φ , Q p n d , γ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Forget}(c)\\
&\nexists c'\in[k+1].\ \langle c,c'\rangle\in Q_{\mathrm{pnd}}\lor\langle c',c\rangle\in Q_{\mathrm{pnd}}\\
&\nexists t\in\operatorname{Tid}.\ \gamma(t)=c\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle
\end{aligned} op = Forget ( c ) ∄ c ′ ∈ [ k + 1 ] . ⟨ c , c ′ ⟩ ∈ Q pnd ∨ ⟨ c ′ , c ⟩ ∈ Q pnd ∄ t ∈ Tid . γ ( t ) = c ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC , Φ , Q pnd , γ ⟩
op = Forget ( c ) ∄ c ′ ∈ [ k + 1 ] . ⟨ c , c ′ ⟩ ∈ Q p n d ∨ ⟨ c ′ , c ⟩ ∈ Q p n d γ ( t ) = c γ ′ = γ [ t ↦ ⊥ ] ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC , Φ , Q p n d , γ ′ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Forget}(c)\\
&\nexists c'\in[k+1].\ \langle c,c'\rangle\in Q_{\mathrm{pnd}}\lor\langle c',c\rangle\in Q_{\mathrm{pnd}}\\
&\gamma(t)=c\quad\gamma'=\gamma[t\mapsto\bot]\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma'\rangle
\end{aligned} op = Forget ( c ) ∄ c ′ ∈ [ k + 1 ] . ⟨ c , c ′ ⟩ ∈ Q pnd ∨ ⟨ c ′ , c ⟩ ∈ Q pnd γ ( t ) = c γ ′ = γ [ t ↦ ⊥ ] ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC , Φ , Q pnd , γ ′ ⟩
op = Intro s b ( c 1 , c 2 ) ⟨ c 1 , c 2 ⟩ ∈ Q p n d Q p n d ′ = Q p n d ∖ { ⟨ c 1 , c 2 ⟩ } ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC , Φ , Q p n d ′ , γ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}_{\mathrm{sb}}(c_1,c_2)\quad\langle c_1,c_2\rangle\in Q_{\mathrm{pnd}}\quad Q'_{\mathrm{pnd}}=Q_{\mathrm{pnd}}\setminus\{\langle c_1,c_2\rangle\}\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC},\Phi,Q'_{\mathrm{pnd}},\gamma\rangle
\end{aligned} op = Intro sb ( c 1 , c 2 ) ⟨ c 1 , c 2 ⟩ ∈ Q pnd Q pnd ′ = Q pnd ∖ {⟨ c 1 , c 2 ⟩} ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC , Φ , Q pnd ′ , γ ⟩
op = Intro b ( c 1 , c 2 ) b ∈ { rf , mb } ⟨ PC , Φ , Q p n d , γ ⟩ → op ⟨ PC , Φ , Q p n d , γ ⟩ \begin{aligned}
&\operatorname{op}=\operatorname{Intro}_b(c_1,c_2)\quad b\in\{\operatorname{rf},\operatorname{mb}\}\\
&\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle\xrightarrow{\operatorname{op}}\langle\operatorname{PC},\Phi,Q_{\mathrm{pnd}},\gamma\rangle
\end{aligned} op = Intro b ( c 1 , c 2 ) b ∈ { rf , mb } ⟨ PC , Φ , Q pnd , γ ⟩ op ⟨ PC , Φ , Q pnd , γ ⟩
Lemma 6.3. Consider a concurrent program P given as a collection of instruction sequences ⟨ S t ⟩ t ∈ Tid \langle S_t\rangle_{t\in\operatorname{Tid}} ⟨ S t ⟩ t ∈ Tid , and their respective LTSs ⟨ P s e q t ⟩ t ∈ Tid \langle Pseq_t\rangle_{t\in\operatorname{Tid}} ⟨ P se q t ⟩ t ∈ Tid . For every k ∈ N k\in\mathbb{N} k ∈ N , there exists a word automaton A s k A_s^k A s k with O ( n ∣ Tid ∣ ⋅ ( ∣ Val ∣ + 1 ) ⋅ 2 O ( ( k + ∣ Tid ∣ ) log k ) ) O(n|\operatorname{Tid}|\cdot(|\operatorname{Val}|+1)\cdot2^{O((k+|\operatorname{Tid}|)\log k)}) O ( n ∣ Tid ∣ ⋅ ( ∣ Val ∣ + 1 ) ⋅ 2 O (( k + ∣ Tid ∣ ) l o g k ) ) states, where n = max t ∈ Tid n t n=\max_{t\in\operatorname{Tid}}n_t n = max t ∈ Tid n t , such that, for every w ∈ L ( A w f k ) w\in\mathcal{L}(A_{\mathrm{wf}}^k) w ∈ L ( A wf k ) , A s k A_s^k A s k accepts w w w iff w w w is canonical and ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) \langle G^w.E,G^w.\operatorname{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Proof. Let w w w be closed, with G w G^w G w an execution graph, and fix t ∈ Tid t\in\operatorname{Tid} t ∈ Tid . As sb restricted to E t E^t E t is a successor relation, let e 1 → sb ⋯ → sb e m e_1\xrightarrow{\operatorname{sb}}\cdots\xrightarrow{\operatorname{sb}}e_m e 1 sb ⋯ sb e m enumerate E t E^t E t .
Soundness. Suppose A s k A_s^k A s k has a run on w w w . A pair ⟨ c 1 , c 2 ⟩ \langle c_1,c_2\rangle ⟨ c 1 , c 2 ⟩ enters Q p n d Q_{\mathrm{pnd}} Q pnd only at the Intro of the event of c 2 c_2 c 2 , with c 1 = γ ( t ) c_1=\gamma(t) c 1 = γ ( t ) the color of an event of t t t introduced before it, and Intro s b ( c 1 , c 2 ) \operatorname{Intro}_{\mathrm{sb}}(c_1,c_2) Intro sb ( c 1 , c 2 ) requires ⟨ c 1 , c 2 ⟩ ∈ Q p n d \langle c_1,c_2\rangle\in Q_{\mathrm{pnd}} ⟨ c 1 , c 2 ⟩ ∈ Q pnd . Hence every sb-edge of G w G^w G w goes from an event to one introduced later, and w w w is canonical. It follows that e 1 , … , e m e_1,\ldots,e_m e 1 , … , e m are introduced in this order. The Intro rules for t t t and the silent rules for t t t are the rules of Section A.1 applied to ⟨ PC ( t ) , Φ ∣ Reg t ⟩ \langle\operatorname{PC}(t),\Phi|_{\operatorname{Reg}_t}\rangle ⟨ PC ( t ) , Φ ∣ Reg t ⟩ , and the other rules leave this pair unchanged. So the steps of the run that concern t t t form a run of P s e q t Pseq_t P se q t from init t \operatorname{init}_t init t emitting lab ( e 1 ) ⋯ lab ( e m ) \operatorname{lab}(e_1)\cdots\operatorname{lab}(e_m) lab ( e 1 ) ⋯ lab ( e m ) , i.e., G w ∣ sb t ∈ L ( P s e q t ) G^w|_{\operatorname{sb}}^t\in\mathcal{L}(Pseq_t) G w ∣ sb t ∈ L ( P se q t ) . As it is arbitrary, ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) \langle G^w.E,G^w.\operatorname{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) .
Completeness. Suppose w w w is canonical and ⟨ G w . E , G w . s b ⟩ ∈ G ( P ) \langle G^w.E,G^w.\mathrm{sb}\rangle\in\mathcal{G}(P) ⟨ G w . E , G w . sb ⟩ ∈ G ( P ) . By canonicity, e 1 , … , e m e_1,\ldots,e_m e 1 , … , e m are introduced in this order, and some run ρ t \rho_t ρ t of P s e q t \mathrm{Pseq}_t Pseq t from i n i t t \mathrm{init}_t init t emits l a b ( e 1 ) ⋯ l a b ( e m ) \mathrm{lab}(e_1)\cdots\mathrm{lab}(e_m) lab ( e 1 ) ⋯ lab ( e m ) . We build a run of A k s A_k^s A k s on w w w : before the Intro of e i e_i e i , apply the silent steps of ρ t \rho_t ρ t that precede its i i i -th labeled transition, and at the Intro apply the rule for the instruction at the current P C ( t ) \mathrm{PC}(t) PC ( t ) . That rule is the one executing the i i i -th labeled transition of ρ t \rho_t ρ t : the instruction is the same, and for a CAS the label, an rmw or a r with a sibling annotation, selects the rule. It remains to check the premises of Introsb and Forget. The edge e i ⟶ s b e i + 1 e_i \mathrel{\stackrel{\mathrm{sb}}{\longrightarrow}} e_{i+1} e i ⟶ sb e i + 1 is drawn when both events are colored, and e i + 1 e_{i+1} e i + 1 is introduced after e i e_i e i , so e i e_i e i is still colored when e i + 1 e_{i+1} e i + 1 is introduced. At that point γ ( t ) \gamma(t) γ ( t ) is the color c 1 c_1 c 1 of e i e_i e i , so the rule adds ⟨ c 1 , c 2 ⟩ \langle c_1,c_2\rangle ⟨ c 1 , c 2 ⟩ to Q p n d Q_{\mathrm{pnd}} Q pnd , which Introsb( c 1 , c 2 ) (c_1,c_2) ( c 1 , c 2 ) then finds. Conversely, each pending pair is removed by the unique Introsb drawing its edge, which precedes the Forget of either endpoint, so the premises of Forget hold. All states are accepting, so w w w is accepted.
Finally, we count the states. P C \mathrm{PC} PC takes ∏ t ( n t + 1 ) ≤ 2 ∣ T i d ∣ ⋅ n ∣ T i d ∣ \prod_{t}(n_t+1)\leq2^{|\mathrm{Tid}|}\cdot n^{|\mathrm{Tid}|} ∏ t ( n t + 1 ) ≤ 2 ∣ Tid ∣ ⋅ n ∣ Tid ∣ values and Φ \Phi Φ takes ( ∣ V a l ∣ + 1 ) ∣ R e g ∣ (|\mathrm{Val}|+1)^{|\mathrm{Reg}|} ( ∣ Val ∣ + 1 ) ∣ Reg ∣ . Each color has at most one Q p n d Q_{\mathrm{pnd}} Q pnd -predecessor and at most one Q p n d Q_{\mathrm{pnd}} Q pnd -successor, both set at the Intro of its event, so Q p n d Q_{\mathrm{pnd}} Q pnd is a partial injection [ k + 1 ] ⇀ [ k + 1 ] [k+1]\rightharpoonup[k+1] [ k + 1 ] ⇀ [ k + 1 ] , with 2 O ( k log k ) 2^{O(k\log k)} 2 O ( k l o g k ) values, and γ \gamma γ takes ( k + 2 ) ∣ T i d ∣ (k+2)^{|\mathrm{Tid}|} ( k + 2 ) ∣ Tid ∣ values. □
G Proofs of SEC:RELAXED
Undecidability of Reachability
Theorem 7.1. State reachability under Relaxed is undecidable, already over programs with two threads and two memory locations.
We prove Theorem 7.1 by a reduction from PCP [55 ] .
Post’s Correspondence Problem. An instance I I I of PCP consists of two tuples ⟨ u 1 , … , u n ⟩ \langle u_1,\ldots,u_n\rangle ⟨ u 1 , … , u n ⟩ and ⟨ v 1 , … , v n ⟩ \langle v_1,\ldots,v_n\rangle ⟨ v 1 , … , v n ⟩ of non-empty words over an alphabet Γ \Gamma Γ . A solution of I I I is a non-empty sequence j 1 , … , j m ∈ [ n ] j_1,\ldots,j_m\in[n] j 1 , … , j m ∈ [ n ] with u j 1 ⋯ u j m = v j 1 ⋯ v j m u_{j_1}\cdots u_{j_m}=v_{j_1}\cdots v_{j_m} u j 1 ⋯ u j m = v j 1 ⋯ v j m . Deciding whether I I I has a solution is undecidable [55 ] . We write u [ k ] u[k] u [ k ] for the k k k -th letter of a word u u u .
The reduction. Given an instance I I I of PCP, we construct the program P I P_I P I of Figure 9 a, with two threads t 1 , t 2 t_1,t_2 t 1 , t 2 and two locations p , q p,q p , q . Both threads guess a solution, one index at a time. For each guessed index j j j , thread t 1 t_1 t 1 writes j j j to p p p and then the letters of u j u_j u j to q q q . Similarly, thread t 2 t_2 t 2 writes j j j to p p p and then the letters of v j v_j v j to q q q . Every value written is a pair ⟨ t , v ⟩ \langle t,v\rangle ⟨ t , v ⟩ of the writing thread and index or a letter ν \nu ν . Every read expects a value of the other thread, together with the index or letter that the reading thread has guessed at that point. So, each read checks that the other thread has written the same index or letter. Note that t 1 t_1 t 1 writes before it reads, while t 2 t_2 t 2 reads before it writes. Finally, each thread ends by emitting term . Since the values range over a finite set, each thread of P I P_I P I is a finite LTS. Note that the two threads advance on p p p and on q q q at different rates, since ∣ u j ∣ ≠ ∣ v j ∣ \lvert u_j\rvert\ne\lvert v_j\rvert ∣ u j ∣ = ∣ v j ∣ in general. This lag creates (poloc ∪ \cup ∪ rf)-cycles, as in Figure 9 b, but these are allowed by Relaxed.
Figure 9. The program P I P_I P I (a), and its execution graph for the instance u = ⟨ a b , b ⟩ u=\langle ab,b\rangle u = ⟨ ab , b ⟩ , v = ⟨ a , b b ⟩ v=\langle a,bb\rangle v = ⟨ a , bb ⟩ and the solution 1, 2, with mb-edges omitted, and the thick rf-edges forming a (po ∪ \cup ∪ rf)-cycle (b).
The correctness of the above construction is captured by the following lemma. Intuitively, in each iteration, each thread reads and writes the same value on p p p (e.g., w ( p , ⟨ t 1 , j ⟩ ) \mathrm{w}(p,\langle t_1,j\rangle) w ( p , ⟨ t 1 , j ⟩) and r ( p , ⟨ t 2 , j ⟩ ) \mathrm{r}(p,\langle t_2,j\rangle) r ( p , ⟨ t 2 , j ⟩) for t 1 t_1 t 1 ) or q q q (e.g., w ( q , ⟨ t 1 , u j [ k ] ⟩ ) \mathrm{w}(q,\langle t_1,u_j[k]\rangle) w ( q , ⟨ t 1 , u j [ k ]⟩) and r ( q , ⟨ t 2 , u j [ k ] ⟩ ) \mathrm{r}(q,\langle t_2,u_j[k]\rangle) r ( q , ⟨ t 2 , u j [ k ]⟩) for t 1 t_1 t 1 ). The crux of the proof is in arguing that no thread can skip reading any of the writes of the other. This implies that the sequences of indices and letters read by each thread are the same. Therefore, whenever both threads reach term , the sequence of indices written to p p p constitutes a solution of I I I .
Lemma G.1. Some G ∈ ⟦ P I ⟧ R e l a x e d G \in\llbracket P_I\rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P I ] ] Relaxed reaches term iff I I I has a solution.
Proof. We first show that the two threads stay in sync. Let G ∈ ⟦ P I ⟧ R e l a x e d G \in\llbracket P_I\rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P I ] ] Relaxed reach term and z ∈ { p , q } z \in\{p,q\} z ∈ { p , q } . We claim that t 1 t_1 t 1 and t 2 t_2 t 2 write equally often on z z z , and that, for every k k k , the k k k -th read of each thread on z z z reads from the k k k -th write of the other thread on z z z . As G G G reaches term , each thread completes every iteration it starts. Let n 1 n_1 n 1 and n 2 n_2 n 2 be the number of writes of t 1 t_1 t 1 and t 2 t_2 t 2 on z z z . We write w k 1 , r k 1 w_k^1,r_k^1 w k 1 , r k 1 for the k k k -th write and read of t 1 t_1 t 1 on z z z , and w k 2 , r k 2 w_k^2,r_k^2 w k 2 , r k 2 for those of t 2 t_2 t 2 . By construction, t 1 t_1 t 1 accesses z z z in the order w 1 1 , r 1 1 , w 2 1 , r 2 1 , … w_1^1,r_1^1,w_2^1,r_2^1,\ldots w 1 1 , r 1 1 , w 2 1 , r 2 1 , … , and t 2 t_2 t 2 in the order r 1 2 , w 1 2 , r 2 2 , w 2 2 , … r_1^2,w_1^2,r_2^2,w_2^2,\ldots r 1 2 , w 1 2 , r 2 2 , w 2 2 , … , each with as many reads as writes. The values force every r k 1 r_k^1 r k 1 to read from t 2 t_2 t 2 and every r k 2 r_k^2 r k 2 to read from t 1 t_1 t 1 .
As G ⊨ R e l a x e d G \models\mathrm{Relaxed} G ⊨ Relaxed , the relation poloc ∪ \cup ∪ rf ∪ \cup ∪ mo ∪ \cup ∪ fr is acyclic on the accesses to z z z . Let S S S be a total order on these accesses that extends it. Every read reads from the S S S -last write before it. Indeed, let w r f → r w \mathrel{\mathrm{rf}\to} r w rf → r and let w ′ w' w ′ be a write with w < S w ′ < S r w <_S w' <_S r w < S w ′ < S r . As S S S extends mo, we have w m o → w ′ w \mathrel{\mathrm{mo}\to} w' w mo → w ′ , and thus r f r → w ′ r \mathrel{\mathrm{fr}\to} w' r fr → w ′ , contradicting w ′ < S r w' <_S r w ′ < S r .
The write w k 1 w_k^1 w k 1 precedes r k 1 r_k^1 r k 1 in S S S , and the S S S -last write before r k 1 r_k^1 r k 1 belongs to t 2 t_2 t 2 . Hence some write of t 2 t_2 t 2 lies between w k 1 w_k^1 w k 1 and r k 1 r_k^1 r k 1 , and thus between w k 1 w_k^1 w k 1 and w k + 1 1 w_{k+1}^1 w k + 1 1 . Symmetrically, some write of t 1 t_1 t 1 lies before r k 2 r_k^2 r k 2 , and between w k − 1 2 w_{k-1}^2 w k − 1 2 and r k 2 r_k^2 r k 2 , and thus between w k − 1 2 w_{k-1}^2 w k − 1 2 and w k 2 w_k^2 w k 2 . So the writes on z z z alternate in S S S , starting with t 1 t_1 t 1 , as w 1 1 , w 1 2 , w 2 1 , w 2 2 , … w_1^1,w_1^2,w_2^1,w_2^2,\ldots w 1 1 , w 1 2 , w 2 1 , w 2 2 , … . The read r k 1 r_k^1 r k 1 requires a write of t 2 t_2 t 2 after w k 1 w_k^1 w k 1 , so n 2 ≥ n 1 n_2 \ge n_1 n 2 ≥ n 1 . The read r k 2 r_k^2 r k 2 requires a write of t 1 t_1 t 1 after w n 2 − 1 2 w_{n_2-1}^2 w n 2 − 1 2 , so n 1 ≥ n 2 n_1 \ge n_2 n 1 ≥ n 2 .
Finally, the read r k 1 r_k^1 r k 1 reads a write of t 2 t_2 t 2 between w k 1 w_k^1 w k 1 and w k + 1 1 w_{k+1}^1 w k + 1 1 , and the only such write is w k 2 w_k^2 w k 2 . The read r k 2 r_k^2 r k 2 reads a write of t 1 t_1 t 1 between w k − 1 2 w_{k-1}^2 w k − 1 2 and w k 2 w_k^2 w k 2 , and the only such write is w k 1 w_k^1 w k 1 .
Soundness. Let G ∈ ⟦ P I ⟧ R e l a x e d G \in\llbracket P_I\rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P I ] ] Relaxed reach term . Let j 1 , … , j m j_1,\ldots,j_m j 1 , … , j m and j 1 ′ , … , j m ′ ′ j'_1,\ldots,j'_{m'} j 1 ′ , … , j m ′ ′ be the indices guessed by t 1 t_1 t 1 and t 2 t_2 t 2 , with m , m ′ ≥ 1 m,m' \ge1 m , m ′ ≥ 1 by construction. By the claim on p p p , we have m = m ′ m=m' m = m ′ , and the k k k -th read of t 1 t_1 t 1 on p p p reads ⟨ t 2 , j k ′ ⟩ \langle t_2,j'_k\rangle ⟨ t 2 , j k ′ ⟩ and expects ⟨ t 2 , j k ⟩ \langle t_2,j_k\rangle ⟨ t 2 , j k ⟩ , so j k = j k ′ j_k=j'_k j k = j k ′ . Thread t 1 t_1 t 1 writes the letters of u j 1 ⋯ u j m u_{j_1}\cdots u_{j_m} u j 1 ⋯ u j m on q q q , and t 2 t_2 t 2 writes those of v j 1 ⋯ v j m v_{j_1}\cdots v_{j_m} v j 1 ⋯ v j m . By the claim on q q q , the two words have equal length, and the k k k -th read of t 1 t_1 t 1 on q q q checks that their k k k -th letters coincide. Hence j 1 , … , j m j_1,\ldots,j_m j 1 , … , j m is a solution of I I I .
Completeness. Let j 1 , … , j m j_1,\ldots,j_m j 1 , … , j m be a solution of I I I . Let both threads guess j 1 , … , j m j_1,\ldots,j_m j 1 , … , j m and reach term , and let G G G be the execution graph with the following rf and mo. On z ∈ { p , q } z \in\{p,q\} z ∈ { p , q } , the k k k -th read of each thread reads from the k k k -th write of the other, and mo orders the writes as w 1 1 , w 1 2 , w 2 1 , w 2 2 , … w_1^1,w_1^2,w_2^1,w_2^2,\ldots w 1 1 , w 1 2 , w 2 1 , w 2 2 , … , in the notation above. The values match, as both threads write j k j_k j k as their k k k -th index and, the sequence being a solution, the same k k k -th letter. The order w 1 1 , r 1 2 , w 1 2 , r 1 1 , w 2 1 , r 2 2 , w 2 2 , r 2 1 , … w_1^1,r_1^2,w_1^2,r_1^1,w_2^1,r_2^2,w_2^2,r_2^1,\ldots w 1 1 , r 1 2 , w 1 2 , r 1 1 , w 2 1 , r 2 2 , w 2 2 , r 2 1 , … on the accesses to z z z extends poloc, rf, mo and fr on z z z . So poloc ∪ \cup ∪ rf ∪ \cup ∪ mo ∪ \cup ∪ fr is acyclic on each location, every realization of it stays on one location, and G ⊨ G \models G ⊨ Relaxed. \hfill □ \square □
Since P I P_I P I has two threads and two locations, Lemma G.1 proves Theorem 7.1 .
The Enclosure
Lemma 7.2. For every concurrent program P P P with two threads, P ′ P' P ′ is robust against Relaxed iff no G ∈ ⟦ P ⟧ R e l a x e d G \in\llbracket P \rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P ] ] Relaxed reaches term .
Proof. As P P P does not access x x x and y y y , the only writes to them in P ′ P' P ′ are the final writes w ( y , 1 ) \mathrm{w}(y,1) w ( y , 1 ) of t 1 t_1 t 1 and w ( x , 1 ) \mathrm{w}(x,1) w ( x , 1 ) of t 2 t_2 t 2 , which follow term .
Suppose that some G ∈ ⟦ P ⟧ R e l a x e d G \in\llbracket P \rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P ] ] Relaxed reaches term . By the definition of state reachability, we may take G G G such that term is the last event of each thread. We build a witness G ′ G' G ′ for P ′ P' P ′ on top of G G G , by adding r ( x , 1 ) \mathrm{r}(x,1) r ( x , 1 ) at the start and w ( y , 1 ) \mathrm{w}(y,1) w ( y , 1 ) at the end of t 1 t_1 t 1 , r ( y , 1 ) \mathrm{r}(y,1) r ( y , 1 ) at the start and w ( x , 1 ) \mathrm{w}(x,1) w ( x , 1 ) at the end of t 2 t_2 t 2 , and the rf-edges from each write to the read of the other thread. Then G ′ G' G ′ is a graph of P ′ P' P ′ , and G ′ ⊨ R e l a x e d G' \models\mathrm{Relaxed} G ′ ⊨ Relaxed , as x x x and y y y each have one write and one read, in different threads, so no cycle on a single location arises. However, the two reads and the two writes form a (po ∪ \cup ∪ rf)-cycle, so G ′ ⊭ S C G' \not\models\mathrm{SC} G ′ ⊨ SC , and P ′ P' P ′ is not robust.
Conversely, let G ′ G' G ′ be a witness for P ′ P' P ′ . As the empty graph is SC-consistent, some thread, say t 1 t_1 t 1 , has an event, which is r ( x , 1 ) \mathrm{r}(x,1) r ( x , 1 ) . Its rf-source is the w ( x , 1 ) \mathrm{w}(x,1) w ( x , 1 ) of t 2 t_2 t 2 , which follows the term of t 2 t_2 t 2 , and the rf-source of the first event r ( y , 1 ) \mathrm{r}(y,1) r ( y , 1 ) of t 2 t_2 t 2 is in turn the w ( y , 1 ) \mathrm{w}(y,1) w ( y , 1 ) of $t_1. Removing the two reads and the two writes yields a graph G ∈ ⟦ P ⟧ R e l a x e d G \in\llbracket P \rrbracket_{\mathrm{Relaxed}} G ∈ [ [ P ] ] Relaxed that reaches term , as every cycle of G G G is also one of G ′ G' G ′ .