5 #include "model-assert.h"
10 static stack_t *stack;
11 static thrd_t *threads;
12 static int num_threads;
14 unsigned int idx1, idx2;
22 thrd_t curr = thrd_current();
24 for (i = 0; i < num_threads; i++)
25 if (curr.priv == threads[i].priv)
31 static void main_task(void *param)
34 int pid = *((int *)param);
37 atomic_store_explicit(&x[1], 17, relaxed);
39 } else if (pid % 4 == 1) {
40 atomic_store_explicit(&x[2], 37, relaxed);
42 } else if (pid % 4 == 2) {/*
45 a = atomic_load_explicit(&x[idx1], relaxed);
51 b = atomic_load_explicit(&x[idx2], relaxed);
57 int user_main(int argc, char **argv)
61 unsigned int in_sum = 0, out_sum = 0;
63 atomic_init(&x[1], 0);
64 atomic_init(&x[2], 0);
66 stack = calloc(1, sizeof(*stack));
69 threads = malloc(num_threads * sizeof(thrd_t));
70 param = malloc(num_threads * sizeof(*param));
72 init_stack(stack, num_threads);
74 for (i = 0; i < num_threads; i++) {
76 thrd_create(&threads[i], main_task, ¶m[i]);
78 for (i = 0; i < num_threads; i++)
79 thrd_join(threads[i]);
82 //correct |= (a == 17 || a == 37 || a == 0);
83 //MODEL_ASSERT(correct);