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) {
41 printf("Thrd 2: Enqueue %d.\n", 1);
42 } else if (pid % 4 == 2) {
45 succ1 = dequeue(queue, &output1);
47 printf("Thrd 3: Dequeue %d.\n", output1);
49 printf("Thrd 3: Dequeue NULL.\n");
53 int user_main(int argc, char **argv)
59 unsigned int in_sum = 0, out_sum = 0;
61 queue = calloc(1, sizeof(*queue));
64 threads = malloc(num_threads * sizeof(thrd_t));
65 param = malloc(num_threads * sizeof(*param));
66 input = calloc(num_threads, sizeof(*input));
67 output = calloc(num_threads, sizeof(*output));
69 init_queue(queue, num_threads);
70 for (i = 0; i < num_threads; i++) {
72 thrd_create(&threads[i], main_task, ¶m[i]);
74 for (i = 0; i < num_threads; i++)
75 thrd_join(threads[i]);