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);
29 static void *b(void *obj)
31 r0 = x.load(memory_order_relaxed);
32 r1 = x.load(memory_order_acquire);
33 y.store(11, memory_order_relaxed);
37 static void *c(void *obj)
39 r2 = y.load(memory_order_relaxed);
40 r3 = y.load(memory_order_relaxed);
41 if (r2 == 11 && r3 == 10)
42 x.store(0, memory_order_relaxed);
46 int user_main(int argc, char **argv)
53 printf("Main thread: creating 3 threads\n");
54 pthread_create(&t1,NULL, &a, NULL);
55 pthread_create(&t2,NULL, &b, NULL);
56 pthread_create(&t3,NULL, &c, NULL);
58 pthread_join(t1,NULL);
59 pthread_join(t2,NULL);
60 pthread_join(t3,NULL);
61 printf("Main thread is finished\n");
64 * This condition should not be hit because it only occurs under a
67 bool cycle = (r0 == 1 && r1 == 0 && r2 == 11 && r3 == 10);