3 * @brief MO satisfaction cycle test
5 * This program has a peculiar behavior which is technically legal under the
6 * current C++ memory model but which is a result of a type of satisfaction
7 * cycle. We use this as justification for part of our modifications to the
8 * memory model when proving our model-checker's correctness.
15 #include "model-assert.h"
20 int r0, r1, r2, r3; /* "local" variables */
22 static void a(void *obj)
24 y.store(10, memory_order_relaxed);
25 x.store(1, memory_order_release);
28 static void b(void *obj)
30 r0 = x.load(memory_order_relaxed);
31 r1 = x.load(memory_order_acquire);
32 y.store(11, memory_order_relaxed);
35 static void c(void *obj)
37 r2 = y.load(memory_order_relaxed);
38 r3 = y.load(memory_order_relaxed);
39 if (r2 == 11 && r3 == 10)
40 x.store(0, memory_order_relaxed);
43 int user_main(int argc, char **argv)
50 printf("Main thread: creating 3 threads\n");
51 thrd_create(&t1, (thrd_start_t)&a, NULL);
52 thrd_create(&t2, (thrd_start_t)&b, NULL);
53 thrd_create(&t3, (thrd_start_t)&c, NULL);
58 printf("Main thread is finished\n");
61 * This condition should not be hit because it only occurs under a
64 bool cycle = (r0 == 1 && r1 == 0 && r2 == 11 && r3 == 10);