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 2: Dequeue %d.\n", output1);
40 printf("Thrd 2: Dequeue NULL.\n");
41 } else if (pid % 4 == 1) {
43 succ2 = dequeue(queue, &output2);
45 printf("Thrd 3: Dequeue %d.\n", output2);
47 printf("Thrd 3: Dequeue NULL.\n");
48 } else if (pid % 4 == 2) {
50 enqueue(queue, input);
51 printf("Thrd 4 Enqueue %d.\n", input);
54 enqueue(queue, input);
55 printf("Thrd 5 Enqueue %d.\n", input);
59 int user_main(int argc, char **argv)
68 unsigned int in_sum = 0, out_sum = 0;
70 queue = calloc(1, sizeof(*queue));
71 //MODEL_ASSERT(queue);
74 threads = malloc(num_threads * sizeof(thrd_t));
75 param = malloc(num_threads * sizeof(*param));
76 input = calloc(num_threads, sizeof(*input));
77 output = calloc(num_threads, sizeof(*output));
79 init_queue(queue, num_threads);
80 for (i = 0; i < num_threads; i++) {
82 thrd_create(&threads[i], main_task, ¶m[i]);
84 for (i = 0; i < num_threads; i++)
85 thrd_join(threads[i]);
87 for (i = 0; i < num_threads; i++) {
91 for (i = 0; i < num_threads; i++)
92 printf("input[%d] = %u\n", i, input[i]);
93 for (i = 0; i < num_threads; i++)
94 printf("output[%d] = %u\n", i, output[i]);
95 //MODEL_ASSERT(in_sum == out_sum);