1 #pragma once 2 3 #include "../relacy/relacy_std.hpp" 4 5 6 7 template<int T> 8 struct cas_spurious_fail_test : rl::test_suite<cas_spurious_fail_test<T>, 1, rl::test_result_until_condition_hit> 9 { 10 std::atomic<int> x; 11 std::atomic<int> y; 12 beforecas_spurious_fail_test13 void before() 14 { 15 x.store(0, std::memory_order_relaxed); 16 y.store(0, std::memory_order_relaxed); 17 } 18 threadcas_spurious_fail_test19 void thread(unsigned /*index*/) 20 { 21 int cmp = 0; 22 if (x.compare_exchange_weak(cmp, 1, std::memory_order_seq_cst, std::memory_order_seq_cst)) 23 { 24 cmp = 1; 25 if (x.compare_exchange_weak(cmp, 2, std::memory_order_seq_cst)) 26 { 27 cmp = 0; 28 if (y.compare_exchange_weak(cmp, 1, std::memory_order_seq_cst)) 29 { 30 } 31 else 32 { 33 if (T == 2) RL_UNTIL(true); 34 } 35 } 36 else 37 { 38 if (T == 1) RL_UNTIL(true); 39 } 40 } 41 else 42 { 43 if (T == 0) RL_UNTIL(true); 44 } 45 } 46 }; 47 48