14
14
// To mitigate this, each test is ran enough times such that the chance
15
15
// of spurious success is very low. These tests never spuriously fail.
16
16
17
- // Test cases and their consistent outcomes are from
18
- // http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/
19
- // Based on
20
- // M. Batty, S. Owens, S. Sarkar, P. Sewell and T. Weber,
21
- // "Mathematizing C++ concurrency", ACM SIGPLAN Notices, vol. 46, no. 1, pp. 55-66, 2011.
22
- // Available: https://ss265.host.cs.st-andrews.ac.uk/papers/n3132.pdf.
23
-
24
17
use std:: sync:: atomic:: Ordering :: * ;
25
18
use std:: sync:: atomic:: { AtomicBool , AtomicI32 , Ordering , fence} ;
26
19
use std:: thread:: spawn;
@@ -56,6 +49,7 @@ fn spin_until_bool(loc: &AtomicBool, ord: Ordering, val: bool) -> bool {
56
49
val
57
50
}
58
51
52
+ /// Test matching https://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2017/POPL.pdf, Figure 7
59
53
fn test_corr ( ) {
60
54
let x = static_atomic ( 0 ) ;
61
55
let y = static_atomic ( 0 ) ;
@@ -75,19 +69,25 @@ fn test_corr() {
75
69
let j3 = spawn ( move || { // | |
76
70
spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
77
71
x. load ( Relaxed ) // <----------------------------------------------+
78
- // The two reads on x are ordered by hb, so they cannot observe values
79
- // differently from the modification order. If the first read observed
80
- // 2, then the second read must observe 2 as well.
81
72
} ) ;
82
73
83
74
j1. join ( ) . unwrap ( ) ;
84
75
let r2 = j2. join ( ) . unwrap ( ) ;
85
76
let r3 = j3. join ( ) . unwrap ( ) ;
77
+ // The two reads on x are ordered by hb, so they cannot observe values
78
+ // differently from the modification order. If the first read observed
79
+ // 2, then the second read must observe 2 as well.
86
80
if r2 == 2 {
87
81
assert_eq ! ( r3, 2 ) ;
88
82
}
89
83
}
90
84
85
+ /// This test case is from:
86
+ /// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/, "WRC"
87
+ /// Based on
88
+ /// M. Batty, S. Owens, S. Sarkar, P. Sewell and T. Weber,
89
+ /// "Mathematizing C++ concurrency", ACM SIGPLAN Notices, vol. 46, no. 1, pp. 55-66, 2011.
90
+ /// Available: https://www.cl.cam.ac.uk/~pes20/cpp/popl085ap-sewell.pdf.
91
91
fn test_wrc ( ) {
92
92
let x = static_atomic ( 0 ) ;
93
93
let y = static_atomic ( 0 ) ;
@@ -114,6 +114,8 @@ fn test_wrc() {
114
114
assert_eq ! ( r3, 1 ) ;
115
115
}
116
116
117
+ /// Another test from http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/:
118
+ /// MP (na_rel+acq_na)
117
119
fn test_message_passing ( ) {
118
120
let mut var = 0u32 ;
119
121
let ptr = & mut var as * mut u32 ;
@@ -139,7 +141,8 @@ fn test_message_passing() {
139
141
assert_eq ! ( r2, 1 ) ;
140
142
}
141
143
142
- // LB+acq_rel+acq_rel
144
+ /// Another test from http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/:
145
+ /// LB+acq_rel+acq_rel
143
146
fn test_load_buffering_acq_rel ( ) {
144
147
let x = static_atomic ( 0 ) ;
145
148
let y = static_atomic ( 0 ) ;
0 commit comments