7 #include "model-assert.h"
16 int r1, r2, r3; /* "local" variables */
19 This example illustrates a self-satisfying cycle involving
20 synchronization. A failed synchronization creates the store that
21 causes the synchronization to fail.
23 The C++11 memory model nominally allows r1=0, r2=1, r3=5.
25 This example is insane, we don't support that behavior.
29 static void a(void *obj)
31 z.store((intptr_t)&y, memory_order_relaxed);
32 r1 = y.fetch_add(1, memory_order_release);
33 z.store((intptr_t)&x, memory_order_relaxed);
34 r2 = y.fetch_add(1, memory_order_release);
38 static void b(void *obj)
40 r3 = y.fetch_add(1, memory_order_acquire);
41 void *ptr = (void *)z.load(memory_order_relaxed);
42 z2.store((intptr_t)ptr, memory_order_relaxed);
45 static void c(void *obj)
47 atomic_int *ptr2 = (atomic_int *)z2.load(memory_order_relaxed);
48 (*ptr2).store(5, memory_order_relaxed);
51 int user_main(int argc, char **argv)
57 atomic_init(&z, (intptr_t) &x);
58 atomic_init(&z2, (intptr_t) &x);
60 thrd_create(&t1, (thrd_start_t)&a, NULL);
61 thrd_create(&t2, (thrd_start_t)&b, NULL);
62 thrd_create(&t3, (thrd_start_t)&c, NULL);
68 printf("r1=%d, r2=%d, r3=%d\n", r1, r2, r3);