6 #include "model-assert.h"
10 static thrd_t *threads;
11 static unsigned int *input;
12 static unsigned int *output;
13 static int num_threads;
17 thrd_t curr = thrd_current();
19 for (i = 0; i < num_threads; i++)
20 if (curr.priv == threads[i].priv)
26 static void main_task(void *param)
29 int pid = *((int *)param);
33 enqueue(queue, input[0]);
34 output[0] = dequeue(queue);
37 enqueue(queue, input[1]);
38 output[1] = dequeue(queue);
42 int user_main(int argc, char **argv)
46 unsigned int in_sum = 0, out_sum = 0;
48 queue = calloc(1, sizeof(*queue));
52 threads = malloc(num_threads * sizeof(thrd_t));
53 param = malloc(num_threads * sizeof(*param));
54 input = calloc(num_threads, sizeof(*input));
55 output = calloc(num_threads, sizeof(*output));
57 init_queue(queue, num_threads);
58 for (i = 0; i < num_threads; i++) {
60 thrd_create(&threads[i], main_task, ¶m[i]);
62 for (i = 0; i < num_threads; i++)
63 thrd_join(threads[i]);
65 for (i = 0; i < num_threads; i++) {
69 for (i = 0; i < num_threads; i++)
70 printf("input[%d] = %u\n", i, input[i]);
71 for (i = 0; i < num_threads; i++)
72 printf("output[%d] = %u\n", i, output[i]);
73 MODEL_ASSERT(in_sum == out_sum);