2 * Try to read the same value as a future value twice.
4 * This test should be able to see r1 = r2 = 42. Currently, we never see that
5 * (as of 2/21/13) because the r2 load won't have a potential future value of
6 * 42 at the same time as r1, due to our scheduling (the loads for r1 and r2
7 * must occur before the write of x = 42).
9 * Note that the atomic_int y is simply used to aid in forcing a particularly
10 * interesting scheduling. It is superfluous.
14 #include <stdatomic.h>
21 static void a(void *obj)
23 int r1 = atomic_load_explicit(&x, memory_order_relaxed);
24 int r2 = atomic_load_explicit(&x, memory_order_relaxed);
25 printf("r1 = %d, r2 = %d\n", r1, r2);
28 static void b(void *obj)
30 atomic_store_explicit(&y, 43, memory_order_relaxed);
31 atomic_store_explicit(&x, 42, memory_order_relaxed);
34 int user_main(int argc, char **argv)
41 printf("Main thread: creating 2 threads\n");
42 thrd_create(&t1, (thrd_start_t)&a, NULL);
43 thrd_create(&t2, (thrd_start_t)&b, NULL);
47 printf("Main thread is finished\n");