10 static void a(void *obj)
12 int idx = *((int *)obj);
15 x[idx - 1].load(std::memory_order_relaxed);
18 x[idx].store(1, std::memory_order_relaxed);
20 x[0].load(std::memory_order_relaxed);
23 int user_main(int argc, char **argv)
31 printf("Error: must have N >= 2\n");
36 threads = (thrd_t *)malloc((N + 1) * sizeof(thrd_t));
37 x = (std::atomic_int *)malloc(N * sizeof(std::atomic_int));
38 indexes = (int *)malloc((N + 1) * sizeof(int));
40 for (int i = 0; i < N + 1; i++)
43 for (int i = 0; i < N; i++)
44 atomic_init(&x[i], 0);
46 for (int i = 0; i < N + 1; i++)
47 thrd_create(&threads[i], (thrd_start_t)&a, (void *)&indexes[i]);
49 for (int i = 0; i < N + 1; i++)
50 thrd_join(threads[i]);