-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmm.html
3297 lines (2571 loc) · 114 KB
/
cmm.html
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
<!-- Generated by Lem from ../axiomatic/ntc/cmm.lem. -->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>C/C++ memory model definitions</title>
<link rel="stylesheet" type="text/css" title="cppmem style" media="screen" href="cppmem.css"/>
</head>
<body>
<h1 id="title">C/C++ memory model definitions</h1>
<pre>
<a name="irrefl">(*========================================================================*)
(* *)
(* cppmem model exploration tool *)
(* *)
(* Mark Batty *)
(* Scott Owens *)
(* Jean Pichon *)
(* Susmit Sarkar *)
(* Peter Sewell *)
(* *)
(* This file is copyright 2011, 2012 by the above authors. *)
(* *)
(* Redistribution and use in source and binary forms, with or without *)
(* modification, are permitted provided that the following conditions *)
(* are met: *)
(* 1. Redistributions of source code must retain the above copyright *)
(* notice, this list of conditions and the following disclaimer. *)
(* 2. Redistributions in binary form must reproduce the above copyright *)
(* notice, this list of conditions and the following disclaimer in the *)
(* documentation and/or other materials provided with the distribution. *)
(* 3. The names of the authors may not be used to endorse or promote *)
(* products derived from this software without specific prior written *)
(* permission. *)
(* *)
(* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS *)
(* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *)
(* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *)
(* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY *)
(* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *)
(* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *)
(* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *)
(* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHE *)
(* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *)
(* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN *)
(* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)
(*========================================================================*)
(* emacs fontification -*-caml-*- *)
(*
--- Introduction ---
This file contains a mathematical version of the relaxed memory model
of C11 and C++11, written in the specification language of Lem. Lem
can compile it to Ocaml, HOL, Isabelle or Latex. The basic model is
faithful to the intent of the 2011 standard and included here in
full. In addition, there are several simplified models that either remove
redundant concepts or provide simplifications for programs that
restrict the input language of programs.
There are lots of definitions that make up the models. To help you
navigate them, the following table of contents (with unique key
phrases) can be used to search the document. Where appropriate, there
are comments describing or explaining the definitions. These are
especially important for the top-level definitions of the simplified models.
--- Contents ---
1 - Relational definitions
2 - Type definitions and projections
- 2.1 - Action and location types
- 2.2 - Execution records
- 2.3 - Projection functions
- 2.4 - Location kinds
3 - The preferred model
- 3.1 - Well formed action
- 3.2 - Well formed threads
- 3.3 - Consistent locks
- 3.4 - Well formed reads from mapping
- 3.5 - Happens before
- 3.6 - Consistent SC and modification orders
- 3.7 - Visible side effects and VSSEs
- 3.8 - Consistent reads from mapping
- 3.9 - Undefined behaviour
- 3.10 - Consistent execution
- 3.11 - Preferred model top level judgement
4 - Standard C/C++ model
5 - Model with separate lock order
6 - Model with per-location lock orders
7 - Model with per-location lock orders and sc order
8 - Model with single step mutex synchronisation
9 - Model simplified for programs without consumes
10 - Model simplified for programs without consumes or relaxed
11 - Model simplified for programs without consumes, relaxed, acquires or releases
12 - Model simplified to a single thread, no atomics
13 - Model simplified, single thread, no atomics 2
14 - Model simplified, multi-thread, no atomics, yes locks
*)
(*************************************************** *)
(* 1 - Relational definitions *)
(*************************************************** *)
let irrefl s ord = ∀ (x ∈ s). not ((x,x)∈ ord)
<a name="trans">
let trans s ord = ∀ (x ∈ s) (y ∈ s) (z ∈ s). (((x,y)∈ ord)&& ((y,z)∈ ord))→ ((x,z)∈ ord)
<a name="cross">
let cross S T = { (s,t) | ∀ (s ∈ S) (t ∈ T) | true}
val tc : ∀ 'a. set ('a * 'a) -> set ('a * 'a)
<a name="set_restrict">
let set_restrict rel s = (rel)^cap; (cross s s)
<a name="strict_partial_order">
let strict_partial_order s ord = irrefl s ord && trans s ord
<a name="relation_over">
let relation_over s rel = ∀ ((a,b) ∈ rel). a ∈ s && (b ∈ s)
<a name="inj_on">
let inj_on f A =
(∀ (x ∈ A). (∀ (y ∈ A). (f x = f y)→ (x = y)))
<a name="total">
let total s ord =
(∀ (x ∈ s) (y ∈ s). (x,y)∈ ord || ((y,x)∈ ord || (x = y)))
<a name="strict_total_order_over">
let strict_total_order_over s ord =
relation_over s ord &&
(strict_partial_order s ord &&
total s ord)
<a name="adjacent_less_than">
let adjacent_less_than ord s x y =
(x,y)∈ ord && not (∃ (z ∈ s). (x,z)∈ ord && ((z,y)∈ ord))
<a name="adjacent_less_than_such_that">
let adjacent_less_than_such_that pred ord s x y =
pred x && ((x,y)∈ ord && not (∃ (z ∈ s). pred z && ((x,z)∈ ord && ((z,y)∈ ord))))
(*************************************************** *)
(* 2 - Type definitions and projections *)
(*************************************************** *)
(*************************************************** *)
(* - 2.1 - Action and location types *)
(*************************************************** *)
(**** Cppmem base types ****)
type flexsym = string
type cst =
| Concrete of num
| Symbolic of string
type cvalue =
| Rigid of cst
| Flexible of flexsym
type aid = string
type tid = cvalue
type location = cvalue
type program = num
type memory_order =
| NA
| Seq_cst
| Relaxed
| Release
| Acquire
| Consume
| Acq_rel
type lock_outcome =
Locked
| Blocked
type action =
| Lock of aid * tid * location * lock_outcome
| Unlock of aid * tid * location
| Load of aid * tid * memory_order * location * cvalue
| Store of aid * tid * memory_order * location * cvalue
| RMW of aid * tid * memory_order * location * cvalue * cvalue
| Fence of aid * tid * memory_order
| Blocked_rmw of aid * tid * location
<a name="dummy22">
(*********************************************** *)
(* - 2.2 - Execution records *)
(*********************************************** *)
let dummy22 = true
type location_kind =
Mutex
| Non_Atomic
| Atomic
type pre_execution =
<| actions : set action;
threads : set tid;
lk : location -> location_kind;
sb : set (action * action) ;
asw : set (action * action) ;
dd : set (action * action) ;
(* cd : set (action * action) ;*)
|>
type order_kind =
Global_order
| Per_location_order
type relation_usage_flags =
<| rf_flag : bool;
mo_flag : bool;
sc_flag : bool;
lo_flag :option order_kind;
ao_flag : bool;
tot_flag : bool; |>
type execution_witness =
<| rf : set (action * action);
mo : set (action * action);
sc : set (action * action);
lo : set (action * action);
ao : set (action * action);
tot : set (action * action);
|>
type relation_list = list (string * set (action * action))
type complete_execution = (pre_execution * execution_witness * relation_list)
type program_behaviours =
Defined of set complete_execution
| Undefined
type named_predicate_tree =
Leaf of (complete_execution -> bool)
| Node of list (string * named_predicate_tree)
(*
let rec apply_tree pred_tree X =
let element_apply_and (name,branch) P = apply_tree branch X && P in
match pred_tree with
Leaf p -> p X
| Node l -> List.fold_right element_apply_and l true end
*)
let rec apply_tree pred_tree X =
match pred_tree with
Leaf p -> p X
| Node l -> List.fold_right
(fun (name,branch) P -> apply_tree branch X && P)
l true end
type fault_setgen =
One of (string * (complete_execution -> set action))
| Two of (string * (complete_execution -> set (action * action)))
<a name="each_empty">
let each_empty faults_list X =
let faults_empty f =
match f with
One (name,setgen) -> (setgen X = {})
| Two (name,setgen) -> (setgen X = {}) end in
List.for_all faults_empty faults_list
type opsem_t = program -> pre_execution -> bool
type protocol_t = complete_execution -> bool
<a name="true_protocol">
let true_protocol _ = true
type memory_model =
<| consistent : named_predicate_tree;
relation_calculation : pre_execution -> execution_witness ->
relation_list;
undefined : list fault_setgen;
relation_flags : relation_usage_flags;
|>
val behaviour : memory_model -> protocol_t -> opsem_t -> program -> program_behaviours
<a name="dummy23">
(*************************************************** *)
(* - 2.3 - Projection functions *)
(*************************************************** *)
let dummy23 = true
<a name="aid_of">
let aid_of a =
match a with
| Lock aid _ _ _ -> aid
| Unlock aid _ _ -> aid
| Load aid _ _ _ _ -> aid
| Store aid _ _ _ _ -> aid
| RMW aid _ _ _ _ _ -> aid
| Fence aid _ _ -> aid
| Blocked_rmw aid _ _ -> aid
end
<a name="tid_of">
let tid_of a =
match a with
Lock _ tid _ _ -> tid
| Unlock _ tid _ -> tid
| Load _ tid _ _ _ -> tid
| Store _ tid _ _ _ -> tid
| RMW _ tid _ _ _ _ -> tid
| Fence _ tid _ -> tid
| Blocked_rmw _ tid _ -> tid
end
<a name="loc_of">
let loc_of a =
match a with
Lock _ _ l _ -> Some l
| Unlock _ _ l -> Some l
| Load _ _ _ l _ -> Some l
| Store _ _ _ l _ -> Some l
| RMW _ _ _ l _ _ -> Some l
| Fence _ _ _ -> None
| Blocked_rmw _ _ l -> Some l
end
<a name="value_read_by">
let value_read_by a =
match a with
Load _ _ _ _ v -> Some v
| RMW _ _ _ _ v _ -> Some v
| _ -> None
end
<a name="value_written_by">
let value_written_by a =
match a with
Store _ _ _ _ v -> Some v
| RMW _ _ _ _ _ v -> Some v
| _ -> None
end
<a name="is_lock">
let is_lock a =
match a with
Lock _ _ _ _ -> true
| _ -> false
end
<a name="is_successful_lock">
let is_successful_lock a =
match a with
Lock _ _ _ Locked -> true
| _ -> false
end
<a name="is_blocked_lock">
let is_blocked_lock a =
match a with
Lock _ _ _ Blocked -> true
| _ -> false
end
<a name="is_unlock">
let is_unlock a =
match a with
Unlock _ _ _ -> true
| _ -> false
end
<a name="is_atomic_load">
let is_atomic_load a =
match a with
Load _ _ mo _ _ -> mo <> NA
| _ -> false
end
<a name="is_atomic_store">
let is_atomic_store a =
match a with
Store _ _ mo _ _ -> mo <> NA
| _ -> false
end
<a name="is_RMW">
let is_RMW a =
match a with
RMW _ _ _ _ _ _ -> true
| _ -> false
end
<a name="is_blocked_rmw">
let is_blocked_rmw a =
match a with
Blocked_rmw _ _ _ -> true
| _ -> false
end
<a name="is_NA_load">
let is_NA_load a =
match a with
Load _ _ mo _ _ -> mo = NA
| _ -> false
end
<a name="is_NA_store">
let is_NA_store a =
match a with
Store _ _ mo _ _ -> mo = NA
| _ -> false
end
<a name="is_load">
let is_load a =
match a with
Load _ _ _ _ _ -> true
| _ -> false
end
<a name="is_store">
let is_store a =
match a with
Store _ _ _ _ _ -> true
| _ -> false
end
<a name="is_fence">
let is_fence a =
match a with
Fence _ _ _ -> true
| _ -> false
end
<a name="is_atomic_action">
let is_atomic_action a =
match a with
Load _ _ mo _ _ -> mo <> NA
| Store _ _ mo _ _ -> mo <> NA
| RMW _ _ _ _ _ _ -> true
| _ -> false
end
<a name="is_read">
let is_read a =
match a with
Load _ _ _ _ _ -> true
| RMW _ _ _ _ _ _ -> true
| _ -> false
end
<a name="is_write">
let is_write a =
match a with
Store _ _ _ _ _ -> true
| RMW _ _ _ _ _ _ -> true
| _ -> false
end
<a name="dummy23'">
(* It is important to note that seq_cst atomics are both acquires and releases *)
let dummy23' = true
<a name="is_acquire">
let is_acquire a =
match a with
Load _ _ mo _ _ -> mo ∈ {Acquire;Seq_cst}
| RMW _ _ mo _ _ _ -> mo ∈ {Acquire;Acq_rel;Seq_cst}
| Fence _ _ mo -> mo ∈ {Acquire;Seq_cst}
| _ -> false
end
<a name="is_release">
let is_release a =
match a with
Store _ _ mo _ _ -> mo ∈ {Release;Seq_cst}
| RMW _ _ mo _ _ _ -> mo ∈ {Release;Acq_rel;Seq_cst}
| Fence _ _ mo -> mo ∈ {Release;Seq_cst}
| _ -> false
end
<a name="is_consume">
let is_consume a =
match a with
Load _ _ mo _ _ -> mo = Consume
| _ -> false
end
<a name="is_seq_cst">
let is_seq_cst a =
match a with
Load _ _ mo _ _ -> mo = Seq_cst
| RMW _ _ mo _ _ _ -> mo = Seq_cst
| Fence _ _ mo -> mo = Seq_cst
| _ -> false
end
<a name="threadwise">
let threadwise s rel = ∀ ((a,b) ∈ rel). tid_of a = tid_of b
<a name="locationwise">
let locationwise s rel = ∀ ((a,b) ∈ rel). loc_of a = loc_of b
<a name="per_location_total">
let per_location_total s rel =
∀ (a ∈ s) (b ∈ s). (loc_of a = loc_of b)→
((a,b)∈ rel || ((b,a)∈ rel || (a = b)))
<a name="dummy24">
(**************************************** *)
(* - 2.4 - Location kinds *)
(**************************************** *)
let dummy24 = true
<a name="dummy241">
(* let actions_respect_location_kinds actions lk = *)
(* forall (a IN actions). match loc_of a with *)
(* Some l -> *)
(* match lk l with *)
(* Mutex -> is_lock a || is_unlock a *)
(* | Non_Atomic -> is_NA_load a || is_NA_store a *)
(* | Atomic -> is_NA_store a || is_atomic_action a || is_blocked_rmw a end *)
(* | None -> true *)
(* end *)
let dummy241 = true
<a name="actions_respect_location_kinds">
let actions_respect_location_kinds actions lk =
∀ (a ∈ actions). match a with
| Lock _ _ l _ -> lk l = Mutex
| Unlock _ _ l -> lk l = Mutex
| Load _ _ mo l _ ->
(mo = NA && (lk l = Non_Atomic)) || (lk l = Atomic)
| Store _ _ mo l _ ->
(mo = NA && (lk l = Non_Atomic)) || (lk l = Atomic)
| RMW _ _ _ l _ _ -> lk l = Atomic
| Fence _ _ _ -> true
| Blocked_rmw _ _ l -> lk l = Atomic
end
<a name="is_at_mutex_location">
let is_at_mutex_location lk a =
match loc_of a with
Some l -> (lk l = Mutex)
| None -> false
end
<a name="is_at_non_atomic_location">
let is_at_non_atomic_location lk a =
match loc_of a with
Some l -> (lk l = Non_Atomic)
| None -> false
end
<a name="is_at_atomic_location">
let is_at_atomic_location lk a =
match loc_of a with
Some l -> (lk l = Atomic)
| None -> false
end
<a name="dummy31">
(**************************************** <a name="preferred">*)
(* 3 - The preferred memory_model *)
(**************************************** *)
(* This simplification should be equivalent to the Standard's memory_model
(section 4) (this was verified for earlier versions using the HOL
theorem prover). It removes the complicated notion of VSSE's, whose
force is covered by the coherence requirements. For those looking
to work with C or C++ concurrency, this is the preferred
memory_model. Predicates from this memory_model will be used in those that
follow. *)
(**************************************** *)
(* - 3.1 - Well formed action *)
(**************************************** *)
let dummy31 = true
<a name="locations_of">
let locations_of actions =
{ l | ∀ (Some l ∈ { (loc_of a) | ∀ (a ∈ actions) | true }) | true}
<a name="well_formed_action">
let well_formed_action a =
match a with
| Load _ _ mo _ _ -> mo ∈ {NA;Relaxed;Acquire;Seq_cst;Consume}
| Store _ _ mo _ _ -> mo ∈ {NA;Relaxed;Release;Seq_cst}
| RMW _ _ mo _ _ _ -> mo ∈ {Relaxed;Release;Acquire;Acq_rel;Seq_cst}
| Fence _ _ mo -> mo ∈ {Release;Acquire;Seq_cst}
| _ -> true
end
<a name="dummy32">
(*********************************************** *)
(* - 3.2 - Well formed threads *)
(*********************************************** *)
(*
relation_over Xo.actions Xo.cd &&
threadwise Xo.actions Xo.cd &&
strict_partial_order Xo.actions Xo.cd &&
Xo.cd subset Xo.sb &&
*)
let dummy32 = true
<a name="blocking_observed">
let blocking_observed actions sb =
(∀ (a ∈ actions).
(is_blocked_rmw a || is_blocked_lock a)→
not (∃ (b ∈ actions). (a,b)∈ sb))
<a name="dummy32'">
(* This should really be moved to the undefined behaviour... not sure now.*)
let dummy32' = true
<a name="well_formed_threads">
let well_formed_threads (Xo,_,_) =
(∀ (a ∈ Xo.actions). well_formed_action a)&& (* especially this *)
(actions_respect_location_kinds Xo.actions Xo.lk &&
(blocking_observed Xo.actions Xo.sb &&
(inj_on aid_of Xo.actions &&
((∀ (a ∈ Xo.actions). tid_of a ∈ Xo.threads)&&
(relation_over Xo.actions Xo.sb &&
(relation_over Xo.actions Xo.dd &&
(relation_over Xo.actions Xo.asw &&
(threadwise Xo.actions Xo.sb &&
(threadwise Xo.actions Xo.dd &&
(strict_partial_order Xo.actions Xo.sb &&
(strict_partial_order Xo.actions Xo.dd &&
(Xo.dd subset Xo.sb))))))))))))
<a name="dummy33">
(*********************************************** *)
(* - 3.3 - Consistent locks *)
(*********************************************** *)
let dummy33 = true
<a name="consistent_locks">
let consistent_locks (Xo,Xw,("hb",hb)::_) =
(∀ ((a,c) ∈ Xw.sc).
(is_successful_lock a && (is_successful_lock c && (loc_of a = loc_of c)))→
(∃ (b ∈ Xo.actions). (loc_of a = loc_of b)&& (is_unlock b && ((a,b)∈ Xw.sc && ((b,c)∈ Xw.sc)))))
<a name="dummy34">
(*********************************************** *)
(* - 3.4 - Well formed reads from mapping *)
(*********************************************** *)
let dummy34 = true
<a name="well_formed_rf">
let well_formed_rf (Xo,Xw,_) =
∀ ((a,b) ∈ Xw.rf).
a ∈ Xo.actions && (b ∈ Xo.actions &&
(loc_of a = loc_of b &&
(is_write a && (is_read b &&
(value_read_by b = value_written_by a &&
(∀ (a' ∈ Xo.actions). ((a',b)∈ Xw.rf)→ (a = a')))))))
<a name="dummy35">
(*********************************************** *)
(* - 3.5 - Happens before *)
(*********************************************** *)
let dummy35 = true
<a name="rs_element">
let rs_element head a =
(tid_of a = tid_of head) || is_RMW a
<a name="release_sequence">
let release_sequence actions lk mo a_rel b =
is_release a_rel &&
( (b = a_rel) ||
( rs_element a_rel b && ((a_rel,b)∈ mo &&
(∀ (c ∈ actions). ((a_rel,c)∈ mo && ((c,b)∈ mo))→ rs_element a_rel c)) ) )
<a name="release_sequence_set">
(* let release_sequence_set actions lk mo = *)
(* { (a,b) | forall (a IN actions) (b IN actions) | *)
(* release_sequence actions lk mo a b} *)
let release_sequence_set actions lk mo =
{ (rel,b) | ∀ (rel ∈ actions) (b ∈ actions) |
is_release rel &&
( (b = rel) ||
( (rel,b)∈ mo &&
(rs_element rel b &&
(∀ (c ∈ actions).
((rel,c)∈ mo && ((c,b)∈ mo))→ rs_element rel c)) ) ) }
<a name="hypothetical_release_sequence_set">
let hypothetical_release_sequence_set actions lk mo =
{ (a,b) | ∀ (a ∈ actions) (b ∈ actions) |
is_at_atomic_location lk a &&
(is_write a &&
( (b = a) ||
( (a,b)∈ mo &&
(rs_element a b &&
(∀ (c ∈ actions).
((a,c)∈ mo && ((c,b)∈ mo))→ rs_element a c)) ) )) }
<a name="hypothetical_release_sequence">
let hypothetical_release_sequence actions lk mo a b =
is_at_atomic_location lk a &&
(is_write a &&
( (b = a) ||
( rs_element a b && ((a,b)∈ mo &&
(∀ (c ∈ actions). ((a,c)∈ mo && ((c,b)∈ mo))→ rs_element a c)) ) ))
<a name="synchronizes_with">
(* let hypothetical_release_sequence_set actions lk mo = *)
(* { (a,b) | forall (a IN actions) (b IN actions) | *)
(* hypothetical_release_sequence actions lk mo a b} *)
let synchronizes_with actions sb asw rf lo rs hrs a b =
(* thread sync *)
(a,b)∈ asw ||
( (loc_of a = loc_of b)&& (a ∈ actions && (b ∈ actions &&
( (* mutex sync *)
(* this seems to be the multi loc lo version... *)
(is_unlock a && (is_successful_lock b && ((a,b)∈ lo))) ||
(* rel/acq sync *)
(( is_release a && (is_acquire b && ((tid_of a <> tid_of b)&&
(∃ (c ∈ actions). (a,c)∈ rs && ((c,b)∈ rf) ))) ) ||
(* fence sync *)
(( (tid_of a <> tid_of b)&&
(is_fence a && (is_release a && (is_fence b && (is_acquire b &&
( ∃ (x ∈ actions) (y ∈ actions). (loc_of x = loc_of y)&&
(is_atomic_action x && (is_atomic_action y && (is_write x &&
((a,x)∈ sb && ((y,b)∈ sb &&
( ∃ (z ∈ actions). (x,z)∈ hrs && ((z,y)∈ rf))))))) ))))) ) ||
(( (tid_of a <> tid_of b)&&
(is_fence a && (is_release a && (is_atomic_action b && (is_acquire b &&
( ∃ (x ∈ actions). (loc_of x = loc_of b)&&
(is_atomic_action x && (is_write x && ((a,x)∈ sb &&
( ∃ (z ∈ actions). (x,z)∈ hrs && ((z,b)∈ rf) )))) ))))) ) ||
( (tid_of a <> tid_of b)&&
(is_atomic_action a && (is_release a &&
(is_fence b && (is_acquire b &&
( ∃ (x ∈ actions). (loc_of a = loc_of x)&& (is_atomic_action x &&
((x,b)∈ sb &&
( ∃ (z ∈ actions). (a,z)∈ rs && ((z,x)∈ rf) ))) ))))) )))) ))) )
<a name="synchronizes_with_set">
let synchronizes_with_set actions sb asw rf lo rs hrs =
{ (a,b) | ∀ (a ∈ actions) (b ∈ actions) |
synchronizes_with actions sb asw rf lo rs hrs a b}
<a name="carries_a_dependency_to_set">
let carries_a_dependency_to_set actions sb dd rf = tc ( (rf ^cap; sb)∪ dd )
<a name="dependency_ordered_before">
let dependency_ordered_before actions rf rs cad a d =
a ∈ actions && (d ∈ actions &&
( ∃ (b ∈ actions). is_release a && (is_consume b &&
((∃ (e ∈ actions). (a,e)∈ rs && ((e,b)∈ rf))&&
( (b,d)∈ cad || (b = d) ))) ))
<a name="dependency_ordered_before_set">
let dependency_ordered_before_set actions rf rs cad =
{ (a,b) | ∀ (a ∈ actions) (b ∈ actions) |
dependency_ordered_before actions rf rs cad a b}
<a name="compose">
let compose R1 R2 =
{ (w,z) | ∀ ((w,x) ∈ R1) ((y,z) ∈ R2) | (x = y) }
<a name="inter_thread_happens_before">
let inter_thread_happens_before actions sb sw dob =
let r = sw ∪ dob ∪ (compose sw sb) in
tc (r ∪ (compose sb r))
<a name="consistent_ithb">
let consistent_ithb
(Xo,Xw,("hb",hb)::_::_::("ithb",ithb)::_) =
irrefl Xo.actions ithb
<a name="happens_before">
let happens_before actions sb ithb =
sb ∪ ithb
<a name="dummy36">
(*********************************************** *)
(* - 3.6 - Consistent SC and modification orders *)
(*********************************************** *)
let dummy36 = true
<a name="consistent_sc">
let consistent_sc (Xo,Xw,("hb",hb)::_) =
let all_sc_actions =
{ a | ∀ (a ∈ Xo.actions) |
is_seq_cst a || (is_lock a || is_unlock a) } in
let sc_happens_before = set_restrict hb (all_sc_actions) in
let sc_mod_order = set_restrict Xw.mo all_sc_actions in
strict_total_order_over all_sc_actions Xw.sc &&
(sc_happens_before subset Xw.sc &&
(sc_mod_order subset Xw.sc))
<a name="consistent_mo">
let consistent_mo (Xo,Xw,("hb",hb)::_) =
trans Xo.actions Xw.mo &&
(irrefl Xo.actions Xw.mo &&
(∀ (a ∈ Xo.actions) (b ∈ Xo.actions).
((a,b)∈ Xw.mo)→ (not ((b,a)∈ hb)&&
(((a,b)∈ Xw.mo || ((b,a)∈ Xw.mo))
= ( is_write a && (is_write b &&
((loc_of a = loc_of b)&&
is_at_atomic_location Xo.lk a)) )))))
<a name="dummy37">
(* let consistent_mo_old (Xo,Xw,("hb",hb)::_) = *)
(* (forall (a IN Xo.actions) (b IN Xo.actions). (a,b) IN Xw.mo --> ((loc_of a = loc_of b) && is_write a && is_write b)) && *)
(* ( forall (l IN locations_of Xo.actions). *)
(* match Xo.lk l with *)
(* Atomic -> *)
(* ( let actions_at_l = {a | forall (a IN Xo.actions) | loc_of a = Some l} in *)
(* let writes_at_l = {a | forall (a IN actions_at_l) | is_write a} in *)
(* strict_total_order_over writes_at_l (set_restrict Xw.mo actions_at_l) && *)
(* (* hb is a subset of mo at l *) *)
(* set_restrict hb writes_at_l subset Xw.mo ) *)
(* | _ -> *)
(* ( let actions_at_l = {a | forall (a IN Xo.actions) | loc_of a = Some l} in *)
(* Set.is_empty (set_restrict Xw.mo actions_at_l) ) end *)
(*********************************************** *)
(* - 3.7 - Visible side effects *)
(*********************************************** *)
(* let visible_side_effect actions hb a b = *)
(* (a,b) IN hb && *)
(* is_write a && is_read b && (loc_of a = loc_of b) && *)
(* not ( exists (c IN actions). not (c = a) && not (c = b) && *)
(* is_write c && (loc_of c = loc_of b) && *)
(* (a,c) IN hb && (c,b) IN hb) *)
let dummy37 = true
<a name="visible_side_effect_set">
let visible_side_effect_set actions hb =
{ (a,b) | ∀ ((a,b) ∈ hb) |
is_write a && (is_read b && ((loc_of a = loc_of b)&&
not ( ∃ (c ∈ actions). not (c ∈ {a;b})&&
(is_write c && ((loc_of c = loc_of b)&&
((a,c)∈ hb && ((c,b)∈ hb))))))) }
<a name="dummy38">
(*********************************************** *)
(* - 3.8 - Consistent reads from mapping *)
(*********************************************** *)
let dummy38 = true
<a name="det_read">
let det_read (Xo,Xw,("hb",hb)::_) =
∀ (r ∈ Xo.actions).
is_read r →
(( ∃ (w ∈ Xo.actions).
is_write w && ((loc_of w = loc_of r)&& ((w,r)∈ hb)) ) =
(∃ (w' ∈ Xo.actions). (w',r)∈ Xw.rf))
<a name="consistent_non_atomic_rf">
let consistent_non_atomic_rf (Xo,Xw,("hb",hb)::("vse",vse)::_) =
∀ ((w,r) ∈ Xw.rf). is_at_non_atomic_location Xo.lk r →
((w,r)∈ vse)
<a name="consistent_atomic_rf">
let consistent_atomic_rf (Xo,Xw,("hb",hb)::_) =
∀ ((w,r) ∈ Xw.rf). is_at_atomic_location Xo.lk r →
not ((r,w)∈ hb)
<a name="consistent_non_atomic_read_values">
let consistent_non_atomic_read_values (Xo,Xw,("hb",hb)::("vse",vse)::_) =
∀ (b ∈ Xo.actions).
(is_read b && is_at_non_atomic_location Xo.lk b)→
( if (∃ (a_vse ∈ Xo.actions). (a_vse,b)∈ vse)
then (∃ (a_vse ∈ Xo.actions). (a_vse,b)∈ vse && ((a_vse,b)∈ Xw.rf))
else not (∃ (a ∈ Xo.actions). (a,b)∈ Xw.rf) )
<a name="consistent_non_atomic_read_values_rejig">
let consistent_non_atomic_read_values_rejig (Xo,Xw,("hb",hb)::("vse",vse)::_) =
∀ (b ∈ Xo.actions).
(is_read b && is_at_non_atomic_location Xo.lk b)→
( if (∃ (w ∈ Xo.actions). (w,b)∈ hb && is_write w)
then (∃ (a_vse ∈ Xo.actions). (a_vse,b)∈ vse && ((a_vse,b)∈ Xw.rf))
else not (∃ (a ∈ Xo.actions). (a,b)∈ Xw.rf) )
<a name="no_vsse_consistent_atomic_read_values">
let no_vsse_consistent_atomic_read_values (Xo,Xw,("hb",hb)::("vse",vse)::_) =
∀ (b ∈ Xo.actions).
(is_read b && is_at_atomic_location Xo.lk b)→
( if (∃ (a_vse ∈ Xo.actions). (a_vse,b)∈ vse)
then (∃ (a ∈ Xo.actions). ((a,b)∈ Xw.rf)&& not ((b,a)∈ hb))
else not (∃ (a ∈ Xo.actions). (a,b)∈ Xw.rf) )