3 * @brief Uninitialized loads test
5 * This is a test of the "uninitialized loads" code. While we don't explicitly
6 * initialize y, this example's synchronization pattern should guarantee we
7 * never see it uninitialized.
9 * @todo (12/11/12) this example currently doesn't run properly; it never sees
10 * the behavior where 'flag == 2'.
21 static void a(void *obj)
23 int flag = x.load(std::memory_order_acquire);
24 printf("flag: %d\n", flag);
26 printf("Load: %d\n", y.load(std::memory_order_relaxed));
29 static void b(void *obj)
31 printf("fetch_add: %d\n", x.fetch_add(1, std::memory_order_relaxed));
34 static void c(void *obj)
36 y.store(3, std::memory_order_relaxed);
37 x.store(1, std::memory_order_release);
40 int user_main(int argc, char **argv)
44 std::atomic_init(&x, 0);
46 printf("Thread %d: creating 2 threads\n", thrd_current());
47 thrd_create(&t1, (thrd_start_t)&a, NULL);
48 thrd_create(&t2, (thrd_start_t)&b, NULL);
49 thrd_create(&t3, (thrd_start_t)&c, NULL);
54 printf("Thread %d is finished\n", thrd_current());