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.
13 //#include "librace.h"
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));
27 static void *b(void *obj)
29 printf("fetch_add: %d\n", x.fetch_add(1, std::memory_order_relaxed));
33 static void *c(void *obj)
35 y.store(3, std::memory_order_relaxed);
36 x.store(1, std::memory_order_release);
40 int user_main(int argc, char **argv)
44 std::atomic_init(&x, 0);
46 printf("Main thread: creating 3 threads\n");
47 pthread_create(&t1,NULL, &a, NULL);
48 pthread_create(&t2,NULL, &b, NULL);
49 pthread_create(&t3,NULL, &c, NULL);
51 pthread_join(t1,NULL);
52 pthread_join(t2,NULL);
53 pthread_join(t3,NULL);
54 printf("Main thread is finished\n");