2 * @file addr-satcycle.cc
3 * @brief Address-based 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"
19 atomic_int x[2], idx, y;
21 int r1, r2, r3; /* "local" variables */
23 static void a(void *obj)
25 r1 = idx.load(memory_order_relaxed);
26 x[r1].store(0, memory_order_relaxed);
28 /* Key point: can we guarantee that &x[0] == &x[r1]? */
29 r2 = x[0].load(memory_order_relaxed);
33 static void b(void *obj)
35 r3 = y.load(memory_order_relaxed);
36 idx.store(r3, memory_order_relaxed);
39 int user_main(int argc, char **argv)
43 atomic_init(&x[0], 1);
47 printf("Main thread: creating 2 threads\n");
48 thrd_create(&t1, (thrd_start_t)&a, NULL);
49 thrd_create(&t2, (thrd_start_t)&b, NULL);
53 printf("Main thread is finished\n");
55 printf("r1 = %d\n", r1);
56 printf("r2 = %d\n", r2);
57 printf("r3 = %d\n", r3);
60 * This condition should not be hit because it only occurs under a
63 bool cycle = (r1 == 1 && r2 == 1 && r3 == 1);