We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c678bd7 commit b6eccc6Copy full SHA for b6eccc6
tests/run-pass/atomic.rs
@@ -5,6 +5,7 @@ fn main() {
5
atomic_isize();
6
atomic_u64();
7
atomic_fences();
8
+ weak_sometimes_fails();
9
}
10
11
fn atomic_bool() {
@@ -85,3 +86,17 @@ fn atomic_fences() {
85
86
compiler_fence(Acquire);
87
compiler_fence(AcqRel);
88
89
+
90
+fn weak_sometimes_fails() {
91
+ static ATOMIC: AtomicBool = AtomicBool::new(false);
92
+ let tries = 20;
93
+ for _ in 0..tries {
94
+ let cur = ATOMIC.load(Relaxed);
95
+ // Try (weakly) to flip the flag.
96
+ if ATOMIC.compare_exchange_weak(cur, !cur, Relaxed, Relaxed).is_err() {
97
+ // We succeeded, so return and skip the panic.
98
+ return;
99
+ }
100
101
+ panic!("compare_exchange_weak succeeded {} tries in a row", tries);
102
+}
0 commit comments