-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdissertation-really-old.tex
More file actions
2643 lines (1830 loc) · 116 KB
/
dissertation-really-old.tex
File metadata and controls
2643 lines (1830 loc) · 116 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[11pt]{report}
\usepackage[bookmarks=true,bookmarksopen=true]{hyperref}
\usepackage{url}
\usepackage{datetime}
\usepackage{proof}
\usepackage{enumerate}
\include{notation}
\include{definitions}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\begin{document}
\settimeformat{ampmtime}
\author{Ian Wehrman}
\title{Weak-Memory Local Reasoning\footnote{This is a draft. Please do not distribute without permission.}}
\date{\today, \currenttime}
\maketitle
\begin{abstract}
Program logics are formal logics designed to facilitate specification and correctness reasoning for software programs of a particular programming language. Separation logic, a new program logic for C-like pointer programs, has found great success due in large part to its embodiment of a \emph{local reasoning} principle, in which specifications and proofs are restricted to just those resources---variables, shared memory addresses, locks---used by the program during execution.
Existing program logics make the strong assumption that all threads agree on the value of shared memory at all times. This assumption is unsound, though, for shared-memory concurrent programs with race conditions, like concurrent data structures. Verification of these difficult programs must take into account the weaker models of memory provided by the architectures on which they execute.
In this dissertation, I explicate a local reasoning principle for a weak memory model based on a formal specification of the x86 multiprocessor memory model. I demonstrate this principle with a new program logic for fine-grained concurrent C-like programs that incorporates ideas from separation logic and rely/guarantee. Notably, the logic may be applied soundly to programs with races, for which no general high-level verification techniques exist.
\end{abstract}
\tableofcontents
\listoffigures
\chapter{Introduction} % (fold)
\label{cha:introduction}
Verifying parallel programs is hard.
\section{What's the Problem?} % (fold)
\label{sec:whats-the-problem}
The weak-memory reasoning problem: the key example, and why most existing techniques fail.
% section whats-the-problem (end)
\section{Contributions} % (fold)
\label{sec:contributions}
% section contributions (end)
% chapter introduction (end)
\chapter{Related Work} % (fold)
\label{cha:related_work}
Reasoning directly about hardware models with a model checker \cite{DPN93}, and with abstraction refinement \cite{ChatterjeeDissertation}.
Zhong Shao's TSO CSL proof: \cite{DBLP:conf/esop/FerreiraFS10}.
Tom Ridge's x86-TSO Rely/Guarantee logic: \cite{DBLP:conf/vstte/Ridge10}; operational reasoning about x86-TSO \cite{DBLP:conf/tphol/Ridge07}.
Ernie Cohen's TSO-SC reduction \cite{DBLP:conf/itp/CohenS10}.
% chapter related_work (end)
\chapter{Notation} % (fold)
\label{ch:notation}
Terms are defined in this chapter and throughout the document with the following meta-notation: \[ \mathit{object} \eqdef \mathit{definition}.\] We additionally use the following meta-notation for defining predicates: \[ \mathit{predicate} \iffdef \mathit{definition}.\]
\section{Relations} % (fold)
\label{sec:relations}
Let $R$ be a relation. We define $\relexp{R}{n}$ by natural number induction on $n$: \begin{eqnarray*}
\relexp{R}{0} & \eqdef & \mathrm{Id} \\
\relexp{R}{n + 1} & \eqdef & \relexp{R}{n} \seq R,
\end{eqnarray*} where $R \seq R'$ is relational composition. We write $\tcl{R}$ and $\rtcl{R}$ for the transitive resp.~reflexive-transitive closure of $R$: \begin{eqnarray*}
\tcl{R} & \eqdef & \bigcup_{n \in \setintegers} \relexp{R}{n} \\
\rtcl{R} & \eqdef & \bigcup_{n \in \setnaturals} \relexp{R}{n}
\end{eqnarray*} If $R \subseteq A \times B$ and $A' \subseteq A$, then the restriction of $R$ to $A'$ is written $\restrict{R}{A'}$.
% section relations (end)
\section{Functions} % (fold)
\label{sec:functions}
For a partial function $f$, we write $f(x) = \bot$ to indicate that $f$ is undefined as $x$. Conversely, we write $\defined{f(x)}$ to indicate that $f$ is defined as $x$.
For a function $f$, we write $\funup{f}{\ptup{x}{v}}$ for the updated function \begin{equation}
\label{eq:funup}
\funup{f}{\ptup{x}{v}} \eqdef \lambda y . \begin{cases}
v & \text{if $y = x$} \\
f(y) & \text{otherwise.}
\end{cases}
\end{equation} A single-point partial function is written $\funup{}{\ptup{x}{v}}$.
When $f$ is a functional in $A \tfun (B \tfun C)$, we additionally use the following abbreviation to indicate the result of updating the function at a point in the codomain of $f$: \begin{equation}
\label{eq:recup}
\funup{f}{\ptup{g(x)}{v}} \eqdef \funup{f}{\ptup{g}{\left(\funup{f(g)}{\ptup{x}{v}}\right)}}.
\end{equation}
Deletion from a (partial) function is written as follows: \begin{equation}
\label{eq:fundel}
\fundel{f}{x} \eqdef \funup{f}{\ptup{x}{\bot}}.
\end{equation}
The restriction of a function $f$ to a set $A \subseteq \dom{f}$ is written as is the restriction of relations: $\restrict{f}{A}$. The image of a function $f$ on a subset $A$ of its domain is written $\image{f}{A}$. The inverse image of $f$ w.r.t. a subset $B$ of its codomain is written $\invimage{f}{B}$.
Functions (total or partial) are \emph{compatible}, written $f \funcompat g$ when they agree at the intersection of their domains: \[ f \funcompat g \iffdef \forall x \in \dom{f} \cap \dom{g} \st f(x) = f(g).\] More generally, for an equivalence relation $R$, we say functions are \emph{$R$-compatible}, written $f \compat_R g$, when they agree according to $R$ at the intersection of their domains: \[ f \compat_R g \iffdef \forall x \in \left(\dom{f} \cap \dom{g}\right) \st R(f(x),g(x)).\] In particular, note that $f \compat_{\nil} g$ holds iff $\dom{f} \cap \dom{g} = \nil$.
The result of \emph{overriding} one function $f$ with another $g$, written $f \override g$, is defined as follows: \[ f \override g \eqdef (f \setminus \dom{g}) \cup g.\]
Let $f$ be a partial function $(B \times B) \pfun B$. We can \emph{lift} $f$ to a partial function on maps $(A \pfun B)$, written $\lift{f}$. Let $g,g' \in (A \pfun B)$. Then $\lift{f}(g,h) \in (A \pfun B))$ is defined as follows: \begin{eqnarray*}
\lift{f}(g,g') \eqdef \lambda a . \begin{cases}
g(a) & \text{if $a \notin \dom{g'}$} \\
g'(a) & \text{else if $a \notin \dom{g}$} \\
f(g(a), g'(a)) & \text{else if $(g(a), g'(a)) \in \dom{f}$} \\
\bot & \text{otherwise.}
\end{cases}
\end{eqnarray*}
% section functions (end)
\section{Records} % (fold)
\label{sec:records}
A record literal is written as follows: \[ \reclit{\ptup{n_1}{v_1},\,\ldots,\, \ptup{n_m}{v_m}},\] where the $n_i$ are field names and the $v_i$ are values. We consider records to be special partial functions mapping field names to some codomain. For a record $r$ with field name $n$, we write $r.n$ as an abbreviation for $r(n)$. It is more traditional to treat records as tuples with named projection functions, but by representing records as partial functions we can handle record and function update uniformly; i.e., the result of updating field $n$ of record $r$ with value $v$ is written $\recup{r}{n}{v}$, and is defined as in Equation~\ref{eq:funup}. Similarly, if the codomain at a field is a function, then we denote the result of updating that function in place at one point by writing $\recup{r}{n(x)}{v}$, defined as in Equation~\ref{eq:recup}. By analogy with Equation~\ref{eq:fundel}, we write deletion from a function in a record as \begin{equation}
\label{eq:recdel}
\funup{r}{n \setminus x} \eqdef \funup{r}{\ptup{n(x)}{\bot}}.
\end{equation} Finally, we define a special-purpose abbreviation for appending additional items to a list-type field in a record: \begin{equation}
\label{eq:ptapp}
\funup{r}{\ptapp{n}{m}} \eqdef \funup{r}{\ptup{n}{(r.n \lapp m)}}
\end{equation}
% section records (end)
\section{Lists} % (fold)
\label{sec:lists}
We write $\epsilon$ for the empty list, $x \lcons l$ for adding a single element $x$ to a list $l$, $\lsingle{x}$ for the singleton list with element $x$ (i.e., shorthand for $x \lcons \epsilon$), and $l \lapp l'$ for the concatenation of lists $l$ and $l'$.
For a list $l$, we write $\llen{l}$ for its length, and $\elems{l}$ for the set of elements that appear in the list. The $n^{\text{th}}$ element of a list $l$ is given by $\nth{n}{l}$ when $\llen{l} > n$.
We additionally treat lists $l$ of type $A \times B$ as partial functions $A \pfun B$: \[ l(a) \eqdef \begin{cases}
b & \text{$\exists l,l',b \st l = \left(l' \lapp \lsingle{(a,b)} \lapp l''\right) \text{ and }a \notin \dom{\elems{l''}}$} \\
\bot & \text{otherwise.}
\end{cases}\]
The set of \emph{interleavings} of lists $l$ and $m$, written $l \merge m$, is defined recursively: \begin{eqnarray*}
\epsilon \merge m & \eqdef & \set{m} \\
l \merge \epsilon & \eqdef & \set{l} \\
(a \lcons l') \merge (b \lcons m') & \eqdef & \setof{a \lcons n}{n \in l' \merge (b \lcons m')} \cup \setof{b \lcons n}{n \in (a \lcons l') \merge m'}\\
\end{eqnarray*}
% section lists (end)
\chapter{Background} % (fold)
\label{cha:background}
% section notation (end)
\section{Order Theory} % (fold)
\label{sec:order-theory}
Recall the definition of a closure operator:
\begin{definition}
\label{def:closure}
A function $f : A \tfun A$ is a \emph{closure
operator} if, for all $B,B' \subseteq A$:
\begin{enumerate}
\item $B \subseteq f(B)$,
\item $B \subseteq B'$ implies $f(B) \subseteq f(B')$, and
\item $f(B) = f(f(B))$.
\end{enumerate}
\end{definition}
Let $\prec$ be a quasi-order (i.e., a reflexive-transitive binary
relation) on set $A$. For element $a \in A$ we write
$\downo{\prec}{a}$ for the \emph{down set} of $a$, defined by: \[
\downo{\prec}{a} \eqdef \setof{b \in A}{b \prec a}.\] For any subset $B
\subseteq A$ , we write $\downo{\prec}{B}$ \emph{down closure} of $B$,
defined by: \[ \downo{\prec}{B} \eqdef \bigcup_{b \in B}
\downo{\prec}{b}.\] We call a set $B$ \emph{down closed} iff $B =
\downo{\prec}{B}$. When it is clear from context, we omit the order
symbol and just write $\down{b}$ and $\down{B}$ for the down set of
$b$ and the down closure of $B$, respectively.
\begin{lemma}
\label{lem:down-closure}
Let $\prec$ be a quasi-order on set $A$. Then $\downo{\prec}{-}$ is
a closure operator.
\end{lemma}
\begin{proof}
\begin{enumerate}
\item $B \subseteq \down{B}$:
\Calc{
$b \in B$
\conn{\onlyif}{reflexivity of $\prec$ and definition of $\down{b}$}
$b \in \down{b}$
\conn{\onlyif}{monotonicity of union}
$b \in \bigcup_{b \in B} \down{b}$
\conn{\onlyif}{definition of $\down{B}$}
$b \in \down{B}$.
}
\item $B \subseteq C$ implies $\down{B} \subseteq \down{C}$:
\Calc{
$b \in \down{B}$
\conn{\iff}{definition of $\down{B}$}
$\exists b' \st b \prec b' \conj b' \in B$
\conn{\onlyif}{assumption $B \subseteq C$}
$\exists b' \st b \prec b' \conj b' \in C$
\conn{\iff}{definition of $\down{C}$}
$b \in \down{C}$.
}
\item $\down{B} = \down{\down{B}}$:
\Calc{
$b \in \down{\down{B}}$
\conn{\iff}{definition of $\down{B}$}
$\exists b' \st b \prec b' \conj b' \in \down{B}$
\conn{\iff}{definition of $\down{B}$}
$\exists b' \st b \prec b' \conj (\exists b'' \st b' \prec b''
\conj b'' \in B)$
\conn{\iff}{transitivity of $\prec$}
$\exists b'' \st b \prec b'' \conj b'' \in B$
\conn{\iff}{definition of $\down{B}$}
$b \in \down{B}$.
}
\end{enumerate}
\end{proof}
\begin{lemma}
\label{lem:closure-lattice}
Let $X \subseteq \powerset{A}$ such that $B \in X$ implies $B = \down{B}$.
\begin{enumerate}
\item $\bigcup X = \down{\bigcup X}$,
\item $\bigcap X = \down{\bigcap X}$.
\end{enumerate}
\end{lemma}
\begin{proof}
The arguments are similar; we show the second. From
Lemma~\ref{lem:down-closure}.1, it suffices to show $\down{\bigcap
X} \subseteq \bigcap X$.
\Calc{
$b \in \down{\bigcap X}$
\conn{\iff}{definition of $\down{\bigcap X}$}
$\exists b' \st b \prec b' \conj b' \in \bigcap X$.
\conn{\iff}{set theory}
$\exists b' \st b \prec b' \conj (\forall B \in X \st b' \in B)$.
\conn{\onlyif}{first-order logic}
$\forall B \in X \st \exists b' \st b \prec b' \conj b' \in B$.
\conn{\iff}{definition of $\down{B}$}
$\forall B \in X \st b \in \down{B}$
\conn{\iff}{$B \in X$ implies $B = \down{B}$ by assumption}
$\forall B \in X \st b \in B$
\conn{\iff}{set theory}
$b \in \bigcap X$.
}
\end{proof}
A related operator is known variously as the kernel, interior or dual closure operator. Whereas the closure yields a least upper bound, the kernel (as we shall refer to it in the sequel) yields a greatest upper bound. The definition is as for the closure, but instead of requiring that the operator be inflationary, it is required to be deflationary.
\begin{definition}
\label{def:kernel}
A function $f : A \tfun A$ is a \emph{kernel
operator} if, for all $B,B' \subseteq A$:
\begin{enumerate}
\item $B \supseteq f(B)$,
\item $B \subseteq B'$ implies $f(B) \subseteq f(B')$, and
\item $f(B) = f(f(B))$.
\end{enumerate}
\end{definition}
(FIXME: The definition of $\kernel$ in the assertion section should be moved here.)
% We define an order-theoretic kernel function $\kernel^{\prec}(-)$, analogous to the down-closure function, as follows: \[ \kernel^{\prec}(B) = \bigcap_{b \in B} \downo{\prec}{b}. \] When the ordering $\prec$ is clear from context, we omit it and simply write $\kernel(B)$.
%
% \begin{lemma}
% \label{lem:kernel-closure}
% $\kernel$ is a kernel operator.
% \end{lemma}
% Recall that a \emph{chain} of a partially ordered set $(A,\leq)$ is a totally ordered subset of $A$. A partially ordered set satisfies the \emph{descending chain condition (DCC)} if each of its nonempty chains has a minimum element. For example, any finite, total order satisfies the DCC.
%
% \begin{lemma}\label{lem:dcc}
% Let $(A,\leq)$ be a partial order that satisfies the DCC, $P \subseteq A$, and $x \in A$. Then if $\forall y \leq x \st \exists z \leq y \st P(z)$ holds, so does $\forall y \leq x \st P(y)$.
% \end{lemma}
%
% \begin{proof}
% By way of the contrapositive, we show that $\exists y \leq x \st \forall z \leq y \st \neg P(z)$. Consider the set $C = \setof{y \leq x}{\neg P(y)}$. By assumption $C$ is nonempty, so $\min C$ is thus well defined, with $\min C \leq x$ and $\neg P(\min C)$. But $\min C$ is minimal, and so also $\forall y \leq \min C \st \neg P(y)$.
% \end{proof}
% section order-theory (end)
\section{Memory Models} % (fold)
\label{sec:memory-models}
The x86-TSO memory model: \cite{DBLP:conf/tphol/OwensSS09}.
% section memory-models (end)
\section{Separation Logic} % (fold)
\label{sec:separation-logic}
The Reynolds paper: \cite{DBLP:conf/lics/Reynolds02}.
% section separation-logic (end)
% chapter background (end)
\section{Linearizability} % (fold)
\label{sec:linearizability}
\cite{DBLP:journals/toplas/HerlihyW90} Also Alexey's paper.
% section linearizability (end)
\chapter{The Programming Model}
\section{Universes} % (fold)
\label{sec:universes}
% section types (end)
We write the set of booleans as $\setbooleans$, and write its two members as $\bvt$ and $\bvf$. We take the set of \emph{values} $\setvalues$, to be equal to the set of integers $\setintegers$, and the set of memory \emph{locations} $\setlocations$ to be equal to the set of natural numbers $\setnaturals$.\footnote{Say something about using mathematical integers for values instead of fixed-width bitvectors.} Hence, we have $\setlocations \subseteq \setvalues$. We additionally assume disjoint countable sets of \emph{identifiers} $\setidentifiers$ and \emph{processor names} $\setprocessors$, both disjoint from the other sets.
\section{Single-processor States} % (fold)
\label{sec:sp-states}
In this section we describe a model of an x86-like machine that is sufficient to describe the operation of individual threads executing in isolation. Later, in Section~\ref{sec:mp-states} we describe a more elaborate machine model suitable for describing the operation of multiple threads executing concurrently on distinct processors.
A \emph{store} is a total function in $\setidentifiers \tfun \setvalues$, which is abbreviated as $\setstores$. A \emph{heap} is a finite partial function in $\setlocations \fpfun \setvalues$, abbreviated as $\setheaps$.\footnote{Do I need to define a ``nil'' value and remove it from the domain of heaps? If so, acknowledge Matt Kaufmann for pointing this out.} A \emph{write} is a location-value pair, and \emph{write buffer} is a finite queue of writes, the set of which is abbreviated as $\setbuffers$. % A \emph{buffer array} is a finite partial function $\setprocessors \fpfun \setbuffers$.
A \emph{single-processor state} $\sigma$ is a record, where $\sigma.s$ is a store, $\sigma.h$ is a heap and $\sigma.q$ is a write buffer that satisfies the following condition: \[ \dom{\elems{\sigma.q}} \subseteq \dom{\sigma.h}.\] The set of single-processor states is abbreviated as $\setstates$.
The set of \emph{allocated locations} in a state $\sigma$, written $\alloc{\sigma}$ is defined as follows: \[ \alloc{\sigma} \eqdef \dom{\sigma.h} \cup \dom{\elems{\sigma.q}}. \] Note that the above constraint on the definition of a state implies that every allocated location has a defined value in the heap. (Later, we will relax this requirement, but the definition of the set of allocated locations will remain the same.)
For a set of identifiers $X$, stores $s_1$ and $s_2$ are called \emph{$X$-congruent}, written $s_1 \stcong{X} s_2$, if they agree on the elements of $X$: \[ s_1 \stcong{X} s_2 \iffdef \restrict{s_1}{X} = \restrict{s_2}{X}. \] The relation is lifted to states in the obvious way: \[ \sigma_1 \stcong{X} \sigma_2 \iffdef \sigma_1.s \stcong{X} \sigma_2.s.\]
% We additionally indicate by $\abort$ a special error state, which results from accessing (loading from, storing to or deallocating) an unallocated memory allocation. For a set $A$, we write $A_\abort$ as an abbreviation for $A \uplus \abort$.
\subsection{Flushing Order} % (fold)
\label{sub:flushing}
As described in Section~\ref{sec:memory-models}, states may nondeterministically transition by committing buffered writes to memory. We define a relation $\sigma \taustep \sigma'$ that describes these silent transitions w.r.t~our single-threaded programming model.
\begin{equation}
\begin{split}
\label{eq:taustepat}
\sigma \taustep \sigma' \iffdef {} & \exists \ell, v, q' \st \sigma.q = \lsingle{(\ell,v)}\lapp q' \conj \sigma' = \funup{\sigma}{\ptup{h(\ell)}{v},\,\ptup{q}{q'}} \\
\end{split}
\end{equation}
\begin{lemma}
\label{lem:tau-functional}
For $n \in \setnaturals$, the relation $\exptaustep{n}$ is functional, but not necessarily injective.
\end{lemma}
\begin{proof}
It is clear that there exists at most one $\ell,v,q'$ such that $\sigma.q = \lsingle{(l,v)} \lapp q'$, and so $\taustep$ is functional. Functionality of of $\exptaustep{n}$ follows by induction on $n$ using the fact that functionality is preserved by relational composition. To see that $\taustep$ is not injective, consider \begin{eqnarray*}
\sigma_1 & = & \funup{\sigma}{\ptup{h(\ell)}{1},\,\ptup{q}{\epsilon}} \\
\sigma_2 & = & \funup{\sigma}{\ptup{h(\ell)}{2},\,\ptup{q}{\lsingle{(\ell,1)}}} \\
\sigma_3 & = & \funup{\sigma}{\ptup{h(\ell)}{3},\,\ptup{q}{\lsingle{(\ell,1)}}},
\end{eqnarray*} where $\sigma_2 \taustep \sigma_1$ and $\sigma_3 \taustep \sigma_1$, but $\sigma_2 \neq \sigma_3$.
\end{proof}
The reflexive-transitive closure of this relation, ${\rttaustep}$, is, of course, a partial order. Hence we use the abbreviation $\sigma \poflush \sigma'$ as shorthand for $\sigma \rttaustep \sigma'$.
\begin{lemma}
\label{lem:downset-total}
Down sets $\downo{\poflush}{\sigma}$ are finite and linear.
\end{lemma}
\begin{proof}
A straightforward induction on $\sigma.q$ shows that $\card{\down \sigma} = \llen{\sigma.q} + 1$. For linearity, assume $\sigma_1, \sigma_2 \in \down \sigma$. Hence, there exist $n_1, n_2 \in \setnaturals$ such that $\sigma \exptaustep{n_1} \sigma_1$ and $\sigma \exptaustep{n_2} \sigma_2$. Assume w.l.o.g.~that $n_1 \leq n_2$, and so there exists $n' \in \setnaturals$ such that $n_1 + n' = n_2$. By Lemma~\ref{lem:tau-functional}, $\sigma \exptaustep{n_1} \sigma_1 \exptaustep{n'} \sigma_2$, and hence $\sigma_2 \leq \sigma_1$.
\end{proof}
We define the function $\sflush{\sigma}$ to be the minimum element of $\down \sigma$, which is known to exist by Lemma~\ref{lem:downset-total}.
\begin{equation}
\label{eq:sflush}
\sflush{\sigma} \eqdef \min_{\poflush}\left(\downo{\poflush}\sigma\right)
\end{equation}
For convenience, we also overload the function to its pointwise lifting: \[ \sflush{S} \eqdef \setof{\sflush{\sigma}}{\sigma \in S}.\]
% subsection flushing (end)
% section sp-states (end)
\section{Expressions} % (fold)
\label{sec:expressions}
Expressions are syntactic constructs that denote values. We further categorize expressions according to whether they denote boolean values or integer values. Their grammars are as follows, where $v \in \setvalues$ and $x \in \setidentifiers$:
\begin{align*}
\exprs~e & \bnfdef v \bnfbar x \bnfbar e + e' \bnfbar e - e' \bnfbar \ldots \\
\bexprs~b & \bnfdef \bexpt \bnfbar \bexpf \bnfbar e = e' \bnfbar !b \bnfbar \ldots \\
\end{align*}
We do not bother to specify a complete set of expression constructors once and for all, it being so straightforward to augment the set as needed.
\subsection{Expression Substitution} % (fold)
\label{sub:expression_substitution}
For expressions $e,e'$ and variable $x$, the \emph{expression
substitution} $e\subst{x}{e'}$ is defined by induction on the structure of $e$:
\begin{eqnarray*}
v\subst{x}{e'} &\eqdef& v\\
y\subst{x}{e'} &\eqdef& \begin{cases} e' & \text{if $y = x$} \\
y & \text{otherwise}\end{cases} \\
(e_1 + e_2)\subst{x}{e'} &\eqdef& e_1\subst{x}{e'} + e_2\subst{x}{e'} \\
\vdots~ &\eqdef& ~\vdots
\end{eqnarray*}
For boolean expression $b$, the substitution $b\subst{x}{e'}$ is
defined similarly by induction on $b$:
\begin{eqnarray*}
\bexpt \subst{x}{e'} &\eqdef& \bexpt \\
\bexpf \subst{x}{e'} &\eqdef& \bexpf \\
(e_1 = e_2)\subst{x}{e'} &\eqdef& e_1\subst{x}{e'} = e_2\subst{x}{e'}\\
!b\subst{x}{e'} &\eqdef& !(b\subst{x}{e'}) \\
\vdots~ &\eqdef& ~\vdots
\end{eqnarray*}
% subsection expression_substitution (end)
\subsection{Dynamic Semantics of Expressions} % (fold)
\label{sub:dynamic_semantics_of_expressions}
The dynamic meaning of expressions is given with respect to \emph{stores}, i.e., total functions $\setidentifiers \tfun \setvalues$, abbreviated in the sequel as $\setstores$. Specifically, we define denotation functions $\dnexpr{-}$ and $\dnbexpr{-}$ as total functions $\exprs \tfun (\setstores \tfun \setvalues)$ resp.~$\bexprs \tfun (\setstores \tfun \setvalues)$. These functions\footnote{We also don't bother to distinguish in this document between the natural numbers and the syntactic literals that denote them. We could remedy this by assuming another set $\setvalues^\star$ that is in a one-to-one correspondence with $\setvalues$, and to take $\dnexpr{v^\star} = v$.} are defined in Figure~\ref{fig:dnexpr}.
We use the term \emph{resolvers} to refer to the semantic functions $\dnexpr{e} \in (\setstores \tfun \setvalues)$. The set of resolvers is abbreviated as $\setresolvers$; we typically use the symbol $\rho$ to range over resolvers.
\begin{figure}[h]
\centering
\begin{align*}
\dnexpr{v}s & \eqdef v \\
\dnexpr{x}s & \eqdef s(x) \\
\dnexpr{e + e'}s & \eqdef \dnexpr{e}s + \dnexpr{e'}s \\
\dnexpr{e - e'}s & \eqdef \dnexpr{e}s - \dnexpr{e'}s \\
\vdots~ & \eqdef ~\vdots \\
\dnbexpr{\bexpt}s & \eqdef \bvt \\
\dnbexpr{\bexpf}s & \eqdef \bvf \\
\dnbexpr{e = e'}s & \eqdef \begin{cases}
\bvt & \text{if $\dnexpr{e}s = \dnexpr{e'}s$} \\
\bvf & \text{otherwise.}
\end{cases}\\
\dnbexpr{!b}s & \eqdef \begin{cases}
\bvt & \text{if $\dnbexpr{b}s = \bvf$} \\
\bvf & \text{otherwise.}
\end{cases}\\
\vdots~ & \eqdef ~\vdots
\end{align*}
\caption{The denotation of expressions}
\label{fig:dnexpr}
\end{figure}
For convenience, we overload the function $\dnexpr{-}$ in $\exprs \tfun \setpstates \tfun \setvalues$ such that $\dnexpr{c}\sigma = \dnexpr{c}\sigma.s$, and similarly for $\dnbexpr{-}$.
% subsection dynamic_semantics_of_expressions (end)
\subsection{Static Semantics of Expressions} % (fold)
\label{sub:static_semantics_of_expressions}
The set of free variables of expressions and boolean expressions, written $\fv{e}$ resp.~\fv{b} is defined in Figure~\ref{fig:expfv}.
\begin{figure}[h]
\centering
\begin{align*}
\fv{v} \eqdef {} & \nil \\
\fv{x} \eqdef {} & \set{x} \\
\fv{e + e'} \eqdef {} & \fv{e} \cup \fv{e'} \\
\fv{e - e'} \eqdef {} & \fv{e} \cup \fv{e'} \\
\vdots~ \eqdef {} & ~\vdots \\
\fv{\bexpt} \eqdef {} & \nil \\
\fv{\bexpf} \eqdef {} & \nil \\
\fv{e = e'} \eqdef {} & \fv{e} \cup \fv{e'} \\
\fv{!b} \eqdef {} & \fv{b} \\
\vdots~ \eqdef {} & ~\vdots
\end{align*}
\caption{Free variables of expressions}
\label{fig:expfv}
\end{figure}
\begin{lemma}
\label{lem:expr-fv}
For stores $s_1,s_2$ and expression $e$, if $s_1 \stcong{\fv{e}} s_2$ then $\dnexpr{e}s_1 = \dnexpr{e}s_2$. And similarly for boolean expression $b$, if $s_1 \stcong{\fv{b}} s_2$ then $\dnbexpr{b}s_1 = \dnbexpr{b}s_2$.
\end{lemma}
\begin{proof}
By a trivial induction on the structure of the expression.
\end{proof}
% subsection static_semantics_of_expressions (end)
\subsection{Resolver Update} % (fold)
\label{sub:resolver_update}
For resolvers $\rho,\rho'$ and $x \in \setidentifiers$, the \emph{resolver update} $\rho\subst{x}{\rho'}$ is defined as follows: \[ \rho\subst{x}{\rho'} \eqdef \lambda s \st \rho(\funup{s}{\ptup{x}{\rho'(s)}}). \] In other words, the updated resolver $\rho \subst{i}{\rho'}$ ignores the applied store value at $x$, and instead uses the result of $\rho'$ at that store. Resolver updates are used to describe the semantics of expression substitutions $e \subst{x}{e}$. When resolving a store against $\dnexpr{e}$, instead of querying for the value of $x$, instead $\dnexpr{e'}$ is used to resolve the store, and that value is used instead.
\begin{lemma}
\label{lem:exp-sem-subst}
Let $e,e'$ be expressions and $i \in \setidentifiers$. Then $\dnexpr{e\subst{i}{e'}} = \dnexpr{e}\subst{i}{\dnexpr{e'}}$.
\end{lemma}
\begin{proof}
By induction on the structure of $e$.
\begin{description}
\item[Value:]
\Calc{
$\dnexpr{v\subst{i}{e'}}s$
\conn{=}{definition of expression substitution}
$\dnexpr{v}s$
\conn{=}{definition of $\dnexpr{-}$}
$v$
\conn{=}{definition of $\dnexpr{-}$}
$\dnexpr{v}\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{=}{definition of resolver substitution}
$\dnexpr{v}\subst{i}{\dnexpr{e'}}s$.
}
\item[Identifier:]
First consider $k \neq i$:
\Calc{
$\dnexpr{k\subst{i}{e'}}s$
\conn{=}{definition of expression substitution, assumption $k
\neq i$}
$\dnexpr{k}s$
\conn{=}{definition of $\dnexpr{-}$}
$s(k)$
\conn{=}{set theory, assumption $k \neq i$}
$\funup{s}{\ptup{i}{\dnexpr{e'}s}}(k)$
\conn{=}{definition of $\dnexpr{-}$}
$\dnexpr{k}\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{=}{definition of resolver substitution}
$\dnexpr{k}\subst{i}{\dnexpr{e'}}s$.
}
Next, $k = i$:
\Calc{
$\dnexpr{i\subst{i}{e'}}s$
\conn{=}{definition of expression substitution}
$\dnexpr{e'}s$
\conn{=}{set theory}
$\funup{s}{\ptup{i}{\dnexpr{e'}s}}(i)$
\conn{=}{definition of $\dnexpr{-}$}
$\dnexpr{i}\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{=}{definition of resolver substitution}
$\dnexpr{i}\subst{i}{\dnexpr{e'}}s$.
}
\item[Addition:]
\Calc{
$\dnexpr{(e_1 + e_2)\subst{i}{e'}}s$
\conn{=}{definition of expression substitution}
$\dnexpr{e_1\subst{i}{e'} + e_2\subst{i}{e'}}s$
\conn{=}{definition of $\dnexpr{-}$}
$\dnexpr{e_1\subst{i}{e'}}s + \dnexpr{e_2\subst{i}{e'}}s$
\conn{=}{inductive hypothesis}
$\dnexpr{e_1}\subst{i}{\dnexpr{e'}}s +
\dnexpr{e_2}\subst{i}{\dnexpr{e'}}s$
\conn{=}{definition of resolver substitution}
$\dnexpr{e_1}\funup{s}{\ptup{i}{\dnexpr{e'}s}} +
\dnexpr{e_2}\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{=}{definition of $\dnexpr{-}$}
$(\dnexpr{e_1} + \dnexpr{e_2})\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{=}{definition of resolver substitution}
$(\dnexpr{e_1} + \dnexpr{e_2})\subst{i}{\dnexpr{e'}}s$.
}
\end{description}
\end{proof}
\begin{lemma}
\label{lem:bexp-sem-subst}
Let $b$ be a boolean expression, $e'$ an expression and $i \in \setidentifiers$. Then $\dnexpr{b\subst{i}{e'}} = \dnexpr{b}\subst{i}{\dnexpr{e'}}$.
\end{lemma}
\begin{proof}
\Calc{
$\dnexpr{(e_1 = e_2)\subst{i}{e'}}s = 1$
\conn{\iff}{definition of expression substitution}
$\dnexpr{e_1\subst{i}{e'} = e_2\subst{i}{e'}}s = 1$
\conn{\iff}{definition of $\dnexpr{-}$}
$\dnexpr{e_1\subst{i}{e'}}s = \dnexpr{e_2\subst{i}{e'}}s$
\conn{\iff}{Lemma~\ref{lem:exp-sem-subst}}
$\dnexpr{e_1}\subst{i}{\dnexpr{e'}}s = \dnexpr{e_2}\subst{i}{\dnexpr{e'}}s$
\conn{\iff}{definition of resolver substitution}
$\dnexpr{e_1}\funup{s}{\ptup{i}{\dnexpr{e'}s}} =
\dnexpr{e_2}\funup{s}{\ptup{i}{\dnexpr{e'}s}}$
\conn{\iff}{definition of $\dnexpr{-}$}
$\dnexpr{e_1 = e_2}\funup{s}{\ptup{i}{\dnexpr{e'}s}} =
1$
\conn{\iff}{definition of resolver substitution}
$\dnexpr{e_1 = e_2}\subst{i}{\dnexpr{e'}}s = 1$.
}
\end{proof}
% subsection resolver_substitution (end)
% section expressions (end)
\section{Primitive Commands} % (fold)
\label{sec:primitive_commands}
We use the term ``commands'' to describe both the primitives of the programming language, and the fragments of the programming language that result from applying combinators that create only sequential dependences among the primitives. The primitive commands are given in Figure~\ref{fig:primitive-commands}.
\begin{figure}[h]
\centering
\begin{eqnarray*}
\pcomms~p & \bnfdef & \cskip \bnfbar \cassign{x}{e} \bnfbar \cassume{b} \bnfbar \cload{x}{e} \bnfbar \cstore{e}{e'} \\
& & \bnfbar \cfence \bnfbar \cnew{x}{e} \bnfbar \cfree{e}
\end{eqnarray*}
\caption{The primitive commands}
\label{fig:primitive-commands}
\end{figure}
Informally, $\cskip$ is the identity command, which does nothing. $\cassign{x}{e}$ loads the value of $e$ into the identifier $x$. $\cassume{b}$ does nothing if $b$ evaluates to $\bvt$ and diverges otherwise. $\cload{x}{e}$ loads the value at the address in memory which is the value of $e$ into the variable $x$. $\cstore{e}{e'}$ stores the value of $e'$ into the address in memory which is the value of $e$. $\cfence$ performs a memory fence. $\ccons{x}{e}{e'}$ allocates two consecutive locations in memory, and stores the value of $e$ into the first and $e'$ into the latter. $\cfree{e}$ disposes of the memory at the address which is the value of $e$.
\subsection{Dynamic Semantics of Primitive Commands} % (fold)
\label{sub:dynamic_semantics_of_primitive_commands}
Formally, the meaning of primitive commands is given with respect to a function $\dnpcomm{-}$ in $\pcomms \tfun (\setpstates \pfun \powerset{\setpstates})$. But we define a few auxiliary functions first before presenting the full definition of $\dnpcomm{-}$.
For a resolver $\rho$ and state $\sigma$, we write $\speek{\rho}{\sigma}$ for the value of location $\rho(\sigma.s)$ visible to the processor: \begin{equation}
\label{eq:speek}
\speek{\rho}{\sigma} \eqdef \begin{cases}
\sigma.q(\rho(\sigma.s)) & \text{if $\rho(\sigma.s) \in \dom{\elems{\sigma.q}}$ } \\
\sigma.h(\rho(\sigma.s)) & \text{if $\rho(\sigma.s) \in \dom{\sigma.h}$} \\
\bot & \text{otherwise.}
\end{cases}
\end{equation}
Note that this partial function is only defined when $\rho(\sigma.s) \in
\alloc{\sigma}$.
The full definition of $\dnpcomm{-}$ is given in Figure~\ref{fig:dnpcomm} below.
\begin{figure}[h]
\centering
\begin{eqnarray*}
\dnpcomm{\cskip}\sigma & \eqdef & \set{\sigma} \\
\dnpcomm{\cassign{x}{e}}\sigma & \eqdef & \set{\recup{\sigma}{s(x)}{\dnexpr{e}\sigma}}\\
\dnpcomm{\cassume{b}}\sigma & \eqdef & \begin{cases}
\set{\sigma} & \text{if $\dnexpr{b}\sigma = \bvt$} \\
\emptyset & \text{otherwise.}
\end{cases} \\
\dnpcomm{\cload{x}{e}}\sigma & \eqdef & \begin{cases} \set{\recup{\sigma}{s(x)}{\speek{\dnexpr{e}}{\sigma}}} & \text{if $\dnexpr{e}\sigma \in \alloc{\sigma}$} \\
\bot & \text{otherwise.}
\end{cases} \\
\dnpcomm{\cstore{e}{e'}}\sigma & \eqdef & \begin{cases} \set{\funup{\sigma}{\ptapp{q}{\lsingle{(\dnexpr{e}\sigma, \dnexpr{e'}\sigma}}}} & \text{if $\dnexpr{e}\sigma \in \alloc{\sigma}$} \\
\bot & \text{otherwise.}
\end{cases} \\
\dnpcomm{\cfence}\sigma & \eqdef & \set{\sflush{\sigma}} \\
\dnpcomm{\cnew{x}{e}}\sigma & \eqdef & \setof{\sflush{\funup{\sigma}{\ptup{s(x)}{\ell},\,\ptapp{q}{\lsingle{(\ell,\dnexpr{e}\sigma)}}}}}{\ell \notin \alloc{\sigma}}\\
\dnpcomm{\cfree{e}}\sigma & \eqdef & \begin{cases} \set{\funup{(\sflush{\sigma})}{h \setminus \dnexpr{e}\sigma}} & \text{if $\dnexpr{e}\sigma \in \alloc{\sigma}$} \\
\bot & \text{otherwise.}
\end{cases}
\end{eqnarray*}
\caption{The denotations of primitive commands}
\label{fig:dnpcomm}
\end{figure}
% subsection dynamic_semantics_of_primitive_commands (end)
\subsection{Static Semantics of Primitive Commands} % (fold)
\label{sub:static_semantics_of_primitive_commands}
The set of free variables of a primitive command, written $\fv{p}$, is defined in Figure~\ref{fig:fvpcomm}.
\begin{figure}[h]
\centering
\begin{align*}
\fv{\cskip} \eqdef {} & \nil \\
\fv{\cassign{x}{e}} \eqdef {} & \set{x} \cup \fv{e} \\
\fv{\cassume{b}} \eqdef {} & \fv{b} \\
\fv{\cload{x}{e}} \eqdef {} & \set{x} \cup \fv{e} \\
\fv{\cstore{e}{e'}} \eqdef {} & \fv{e} \cup \fv{e'} \\
\fv{\cfence} \eqdef {} & \nil \\
\fv{\cnew{x}{e}} \eqdef {} & \set{x} \cup \fv{e} \\
\fv{\cfree{e}} \eqdef {} & \fv{e}
\end{align*}
\caption{Free variables of primitive commands}
\label{fig:fvpcomm}
\end{figure}
The set of modified variables of a primitive command, written $\mod{p}$, is defined in Figure~\ref{fig:modpcomm}.
\begin{figure}[h]
\centering
\begin{align*}
\mod{\cskip} \eqdef {} & \nil \\
\mod{\cassign{x}{e}} \eqdef {} & \set{x} \\
\mod{\cassume{b}} \eqdef {} & \nil \\
\mod{\cload{x}{e}} \eqdef {} & \set{x} \\
\mod{\cstore{e}{e'}} \eqdef {} & \nil \\
\mod{\cfence} \eqdef {} & \nil \\
\mod{\cnew{x}{e}} \eqdef {} & \set{x} \\
\mod{\cfree{e}} \eqdef {} & \nil
\end{align*}
\caption{Modified variables of primitive commands}
\label{fig:modpcomm}
\end{figure}
\begin{lemma}
\label{lem:pcomm-fv-abort}
For primitive command $p$, if $\sigma \stcong{\fv{p}} \sigma'$ and $\dnpcomm{p}\sigma = \bot$ then $\dnpcomm{p}\sigma' = \bot$.
\end{lemma}
\begin{proof}
Follows from Lemma~\ref{lem:expr-fv}.
\end{proof}
\begin{lemma}\label{lem:pcomm-fv-step}
For primitive command $p$ and $X \supseteq \fv{p}$, if $\sigma \stcong{X} \sigma'$ and $\sigma_1 \in \dnpcomm{p}\sigma$ then there exists $\sigma'_1$ such that $\sigma_1 \stcong{X} \sigma_1'$ and $\sigma'_1 \in \dnpcomm{p}\sigma'$.
\end{lemma}
\begin{proof}
In every case except $\cfree{e}$, if $\dnpcomm{p}$ is defined, then it defines a singleton set, and it is straightforward to check that the function which is defined preserves the congruence, making frequent use of Lemma~\ref{lem:expr-fv}. For example, in the case of $\cassign{e}{x}$, $\funup{\sigma}{\ptup{s(x)}{\dnexpr{e}\sigma}} \stcong{X} \funup{\sigma'}{\ptup{s(x)}{\dnexpr{e}\sigma'}}$ because $\sigma \stcong{X} \sigma'$ and $\dnexpr{e}\sigma = \dnexpr{e}\sigma'$ by Lemma~\ref{lem:expr-fv}. In the case of $\cfree{e}$, we additionally note that $\dnexpr{e}\sigma = \dnexpr{e}\sigma'$ and $\alloc(\sigma) =\alloc(\sigma')$ when $\sigma \stcong{X} \sigma'$, for $X \supseteq \fv{e}$.
\end{proof}
% subsection static_semantics_of_primitive_commands (end)
% section primitive_commands (end)
\section{Commands} % (fold)
\label{sec:commands}
The grammar that defines the full language of commands is given in Figure~\ref{fig:commands}.
\begin{figure}[h]
\centering
\begin{eqnarray*}
\comms~c & \bnfdef & p \bnfbar \cseq{c}{c'} \bnfbar \cchoice{c}{c'} \bnfbar \cloop{c} \bnfbar \catomic{c}
\end{eqnarray*}
\caption{The grammar of commands.}
\label{fig:commands}
\end{figure}
A command $c$ is \emph{well formed} as long as it does not contain embedded atomic sections. E.g, $\cseq{\catomic{c}}{\catomic{c'}}$ is well formed, but $\catomic{\cseq{c}{\catomic{c'}}}$ is not.
\subsection{Dynamic Semantics of Commands} % (fold)
\label{sub:dynamic_semantics}
The dynamic semantics of commands is given as a structured operational semantics, ala Plotkin \cite{Plotkin:NatSemTR}. A semantic lock is used to distinguish between steps taken within an atomic section (i.e., while holding the lock: $\ell = \bvt$) from those taken outside of an atomic section (i.e., while not holding the lock: $\ell = \bvf$). We use the term \emph{configurations} to refer either to command-state-lock triples. We abbreviate the set of configurations as $\setconfigurations$. The rules for the \emph{internal reduction semantics}, presented in Figure~\ref{fig:comm-red-rel}, yield a relation $\step$ that is a subset of $\setconfigurations \times \setconfigurations$.
\begin{figure}[h]
\begin{tabular}{rr}
\begin{minipage}{.46\textwidth}
\infrule[prim]{\sigma' \in \dnpcomm{p}\sigma}{p,\sigma,\ell \step \cskip,\sigma',\ell}
% \vspace{1em}
%
% \infrule[primA]{\dnpcomm{p}\sigma = \bot}{p,\sigma,\ell \step \abort}
\vspace{1em}
\infrule[seq1]{c_1,\sigma,\ell \step c',\sigma',\ell'}{(\cseq{c_1}{c_2}),\sigma,\ell \step (\cseq{c'}{c_2}),\sigma',\ell'}
\vspace{1em}
\infax[seq2]{(\cseq{\cskip}{c_2}),\sigma,\ell \step c_2,\sigma,\ell}
\vspace{1em}
\infax[ch1]{(\cchoice{c_1}{c_2}),\sigma,\ell \step c_1,\sigma,\ell}
\vspace{1em}
\infax[ch2]{(\cchoice{c_1}{c_2}),\sigma,\ell \step c_2,\sigma,\ell}
% \vspace{1em}
%
% \infrule[seqA]{c_1,\sigma,\ell \step \abort}{(\cseq{c_1}{c_2}),\sigma,\ell \step \abort}
\end{minipage}
&
\begin{minipage}{.5\textwidth}
\infrule[tau]{\sigma \taustep \sigma'}{c,\sigma,\ell \step c,\sigma',\ell}
\vspace{1em}
\infax[lock]{\catomic{c},\sigma,\bvf \step \catomic{c},\sigma,\bvt}
\vspace{1em}
\infrule[atom]{c,\sigma,\bvt \step c',\sigma',\bvt}{\catomic{c},\sigma,\bvt \step \catomic{c'},\sigma',\bvt}
\vspace{1em}
% \infrule[atomA]{c,\sigma,\bvt \step \abort}{\catomic{c},\sigma,\bvt \step \abort}
%
% \vspace{1em}
\infax[unlock]{\catomic{\cskip},\sigma,\bvt \step \cskip,\sigma',\bvf}
\vspace{1em}
\infax[loop]{\cloop{c},\sigma,\ell \step \left(\cchoice{\cskip}{\cseq{c}{\cloop{c}}}\right),\sigma,\ell}
\end{minipage}
\end{tabular}
\caption{Reduction semantics of Commands}
\label{fig:comm-red-rel}
\end{figure}
Some configurations are considered erroneous. For example, a load command $\cload{x}{y}$ paired with a state in which the value of $y$ is not an allocated location in the heap. We call such configurations \emph{aborting configurations}, written $C \step \abort$. Aborting configurations are defined in Figure~\ref{fig:comm-abort-rel}.
\begin{figure}[h]
\begin{tabular}{lll}
\begin{minipage}{.28\textwidth}
\infrule[primA]{\dnpcomm{p}\sigma = \bot}{p,\sigma,\ell \step \abort}
\end{minipage}
&
\begin{minipage}{.33\textwidth}
\infrule[seqA]{c_1,\sigma,\ell \step \abort}{(\cseq{c_1}{c_2}),\sigma,\ell \step \abort}
\end{minipage}
&
\begin{minipage}{.30\textwidth}
\infrule[atomA]{c,\sigma,\bvt \step \abort}{\catomic{c},\sigma,\bvt \step \abort}
\end{minipage}
\end{tabular}
\caption{Abort Semantics of Commands}
\label{fig:comm-abort-rel}
\end{figure}
Note that steps within atomic sections are visible in the internal reduction relation. It will be useful later, in the definition of programs, to derive another relation that hides these steps, called the \emph{external reduction semantics} of a command. The definition is given in Figure~\ref{fig:comm-ext-red-rel}.
\begin{figure}[h]
\centering
\infrule[E-base]{\neg \exists c'' \st c = \catomic{c''} \text{~and~}c,\sigma,\bvf \step c',\sigma',\bvf}{c,\sigma \estep c',\sigma'}
\vspace{1em}
\infrule[E-atom]{c,\sigma,\bvt \rtcl{\step} \cskip,\sigma',\bvt}{\catomic{c},\sigma \estep \cskip,\sigma'}
\vspace{1em}
\infrule[E-seq]{c_1,\sigma \estep c',\sigma'}{(c_1 \seq c_2),\sigma \estep (c' \seq c_2),\sigma'}
\vspace{1em}
\caption{External reduction semantics of commands}
\label{fig:comm-ext-red-rel}
\end{figure}
We similarly define, in Figure~\ref{fig:comm-ext-abort-rel}, the \emph{external abort semantics} of commands. This differs from the internal abort semantics insofar as a a configuration is considered externally erroneous if, after taking any number of internal steps, an erroneous internal configuration is reached.
\begin{figure}[h]
\centering
\infrule[E-baseA]{\neg \exists c'' \st c = \catomic{c''} \text{~and~}c,\sigma,\bvf \step \abort}{c,\sigma \estep \abort}
\vspace{1em}
\infrule[E-atom]{c,\sigma,\bvt \rtcl{\step} \abort}{\catomic{c},\sigma \estep \abort}
\vspace{1em}
\infrule[E-seq]{c_1,\sigma \estep \abort}{(c_1 \seq c_2),\sigma \estep \abort}
\vspace{1em}
\caption{External abort semantics of commands}
\label{fig:comm-ext-abort-rel}
\end{figure}