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.
18 static void a(void *obj)
20 int flag = x.load(std::memory_order_acquire);
21 printf("flag: %d\n", flag);
23 printf("Load: %d\n", y.load(std::memory_order_relaxed));
26 static void b(void *obj)
28 printf("fetch_add: %d\n", x.fetch_add(1, std::memory_order_relaxed));
31 static void c(void *obj)
33 y.store(3, std::memory_order_relaxed);
34 x.store(1, std::memory_order_release);
37 int user_main(int argc, char **argv)
41 std::atomic_init(&x, 0);
43 printf("Main thread: creating 2 threads\n");
44 thrd_create(&t1, (thrd_start_t)&a, NULL);
45 thrd_create(&t2, (thrd_start_t)&b, NULL);
46 thrd_create(&t3, (thrd_start_t)&c, NULL);
51 printf("Main thread is finished\n");