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);
38 printf("Thrd 1 Enqueue %d.\n", 1);
40 } else if (pid % 3 == 1) {
43 printf("Thrd 2 Enqueue %d.\n", 2);
44 } else if (pid %3 == 2) {
47 printf("Thrd 3 Enqueue %d.\n", 3);
48 succ2 = dequeue(queue, &output2);
50 printf("Thrd 3: Dequeue %d.\n", output2);
52 printf("Thrd 3: Dequeue NULL.\n");
56 int user_main(int argc, char **argv)
65 unsigned int in_sum = 0, out_sum = 0;
67 queue = calloc(1, sizeof(*queue));
68 //MODEL_ASSERT(queue);
71 threads = malloc(num_threads * sizeof(thrd_t));
72 param = malloc(num_threads * sizeof(*param));
73 input = calloc(num_threads, sizeof(*input));
74 output = calloc(num_threads, sizeof(*output));
76 init_queue(queue, num_threads);
77 for (i = 0; i < num_threads; i++) {
79 thrd_create(&threads[i], main_task, ¶m[i]);
81 for (i = 0; i < num_threads; i++)
82 thrd_join(threads[i]);
84 for (i = 0; i < num_threads; i++) {
88 for (i = 0; i < num_threads; i++)
89 printf("input[%d] = %u\n", i, input[i]);
90 for (i = 0; i < num_threads; i++)
91 printf("output[%d] = %u\n", i, output[i]);
92 //MODEL_ASSERT(in_sum == out_sum);