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 /** Be careful, we must make these variables to be global so that they will be
27 * 'available' when the execution is generated */
29 unsigned int output1, output2;
31 static void main_task(void *param)
33 int pid = *((int *)param);
36 succ1 = dequeue(queue, &output1);
38 printf("Thrd 1: Dequeue %d.\n", output1);
40 printf("Thrd 1: Dequeue NULL.\n");
41 } else if (pid % 4 == 1) {
44 succ2 = dequeue(queue, &output2);
46 printf("Thrd 2: Dequeue %d.\n", output2);
48 printf("Thrd 2: Dequeue NULL.\n");
52 int user_main(int argc, char **argv)
61 unsigned int in_sum = 0, out_sum = 0;
63 queue = calloc(1, sizeof(*queue));
64 //MODEL_ASSERT(queue);
67 threads = malloc(num_threads * sizeof(thrd_t));
68 param = malloc(num_threads * sizeof(*param));
69 input = calloc(num_threads, sizeof(*input));
70 output = calloc(num_threads, sizeof(*output));
72 init_queue(queue, num_threads);
73 for (i = 0; i < num_threads; i++) {
75 thrd_create(&threads[i], main_task, ¶m[i]);
77 for (i = 0; i < num_threads; i++)
78 thrd_join(threads[i]);
80 for (i = 0; i < num_threads; i++) {
84 for (i = 0; i < num_threads; i++)
85 printf("input[%d] = %u\n", i, input[i]);
86 for (i = 0; i < num_threads; i++)
87 printf("output[%d] = %u\n", i, output[i]);
88 //MODEL_ASSERT(in_sum == out_sum);