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)
27 unsigned int output1, output2;
29 static void main_task(void *param)
31 int pid = *((int *)param);
34 succ1 = dequeue(queue, &output1);
36 printf("Thrd 1: Dequeue %d.\n", output1);
38 printf("Thrd 1: Dequeue NULL.\n");
39 } else if (pid % 4 == 1) {
42 succ2 = dequeue(queue, &output2);
44 printf("Thrd 2: Dequeue %d.\n", output2);
46 printf("Thrd 2: Dequeue NULL.\n");
50 int user_main(int argc, char **argv)
56 unsigned int in_sum = 0, out_sum = 0;
58 queue = calloc(1, sizeof(*queue));
61 threads = malloc(num_threads * sizeof(thrd_t));
62 param = malloc(num_threads * sizeof(*param));
63 input = calloc(num_threads, sizeof(*input));
64 output = calloc(num_threads, sizeof(*output));
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]);