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);
34 static void *b(void *obj)
36 r3 = y.load(memory_order_relaxed);
37 idx.store(r3, memory_order_relaxed);
41 int user_main(int argc, char **argv)
45 atomic_init(&x[0], 1);
49 printf("Main thread: creating 2 threads\n");
50 pthread_create(&t1,NULL, &a, NULL);
51 pthread_create(&t2,NULL, &b, NULL);
53 pthread_join(t1,NULL);
54 pthread_join(t2,NULL);
55 printf("Main thread is finished\n");
57 printf("r1 = %d\n", r1);
58 printf("r2 = %d\n", r2);
59 printf("r3 = %d\n", r3);
62 * This condition should not be hit because it only occurs under a
65 bool cycle = (r1 == 1 && r2 == 1 && r3 == 1);