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);
37 succ1 = dequeue(queue, &idx1, &reclaimNode);
40 succ2 = dequeue(queue, &idx2, &reclaimNode);
44 int user_main(int argc, char **argv)
48 unsigned int in_sum = 0, out_sum = 0;
51 queue = (queue_t*) calloc(1, sizeof(*queue));
55 threads = (thrd_t*) malloc(num_threads * sizeof(thrd_t));
56 param = (int*) malloc(num_threads * sizeof(*param));
57 input = (unsigned int *) calloc(num_threads, sizeof(*input));
58 output = (unsigned int *) calloc(num_threads, sizeof(*output));
60 init_queue(queue, num_threads);
61 for (i = 0; i < num_threads; i++) {
63 thrd_create(&threads[i], main_task, ¶m[i]);
65 for (i = 0; i < num_threads; i++)
66 thrd_join(threads[i]);
68 for (i = 0; i < num_threads; i++) {
72 for (i = 0; i < num_threads; i++)
73 printf("input[%d] = %u\n", i, input[i]);
74 for (i = 0; i < num_threads; i++)
75 printf("output[%d] = %u\n", i, output[i]);
77 MODEL_ASSERT(in_sum == out_sum);