6 #include "model-assert.h"
9 static thrd_t *threads;
10 static unsigned int *input;
11 static unsigned int *output;
12 static int num_threads;
16 thrd_t curr = thrd_current();
18 for (i = 0; i < num_threads; i++)
19 if (curr.priv == threads[i].priv)
27 unsigned int idx1, idx2;
28 unsigned int reclaimNode;
31 static void main_task(void *param)
34 int pid = *((int *)param);
35 if (pid % procs == 0) {
36 //atomic_store_explicit(&x[0], 1, memory_order_relaxed);
38 } else if (pid % procs == 1) {
39 //atomic_store_explicit(&x[1], 1, memory_order_relaxed);
40 succ1 = dequeue(queue, &idx1, &reclaimNode);
42 //atomic_load_explicit(&x[idx1], memory_order_relaxed);
47 int user_main(int argc, char **argv)
51 unsigned int in_sum = 0, out_sum = 0;
54 queue = (queue_t*) calloc(1, sizeof(*queue));
58 threads = (thrd_t*) malloc(num_threads * sizeof(thrd_t));
59 param = (int*) malloc(num_threads * sizeof(*param));
60 input = (unsigned int *) calloc(num_threads, sizeof(*input));
61 output = (unsigned int *) calloc(num_threads, sizeof(*output));
63 atomic_init(&x[0], 0);
64 atomic_init(&x[1], 0);
65 atomic_init(&x[2], 0);
66 init_queue(queue, num_threads);
67 for (i = 0; i < num_threads; i++) {
69 thrd_create(&threads[i], main_task, ¶m[i]);
71 for (i = 0; i < num_threads; i++)
72 thrd_join(threads[i]);
74 for (i = 0; i < num_threads; i++) {
78 for (i = 0; i < num_threads; i++)
79 printf("input[%d] = %u\n", i, input[i]);
80 for (i = 0; i < num_threads; i++)
81 printf("output[%d] = %u\n", i, output[i]);
83 MODEL_ASSERT(in_sum == out_sum);