6 #include "model-assert.h"
9 static thrd_t *threads;
10 static unsigned int *input;
11 static unsigned int *output;
12 static int num_threads;
16 thrd_t curr = thrd_current();
18 for (i = 0; i < num_threads; i++)
19 if (curr.priv == threads[i].priv)
27 unsigned int idx1, idx2;
28 unsigned int reclaimNode;
31 static void main_task(void *param)
34 int pid = *((int *)param);
35 if (pid % procs == 0) {
36 //atomic_store_explicit(&x[0], 1, memory_order_relaxed);
38 printf("T2 enqueue %d\n", 1);
39 succ1 = dequeue(queue, &idx1, &reclaimNode);
41 printf("T2 dequeue %d\n", idx1);
43 printf("T2 dequeue NULL\n");
44 } else if (pid % procs == 1) {
46 printf("T3 enqueue %d\n", 2);
47 succ2 = dequeue(queue, &idx2, &reclaimNode);
49 printf("T3 dequeue %d\n", idx2);
51 printf("T2 dequeue NULL\n");
55 int user_main(int argc, char **argv)
59 unsigned int in_sum = 0, out_sum = 0;
62 queue = (queue_t*) calloc(1, sizeof(*queue));
66 threads = (thrd_t*) malloc(num_threads * sizeof(thrd_t));
67 param = (int*) malloc(num_threads * sizeof(*param));
68 input = (unsigned int *) calloc(num_threads, sizeof(*input));
69 output = (unsigned int *) calloc(num_threads, sizeof(*output));
71 atomic_init(&x[0], 0);
72 atomic_init(&x[1], 0);
73 atomic_init(&x[2], 0);
74 init_queue(queue, num_threads);
75 for (i = 0; i < num_threads; i++) {
77 thrd_create(&threads[i], main_task, ¶m[i]);
79 for (i = 0; i < num_threads; i++)
80 thrd_join(threads[i]);
82 for (i = 0; i < num_threads; i++) {
86 for (i = 0; i < num_threads; i++)
87 printf("input[%d] = %u\n", i, input[i]);
88 for (i = 0; i < num_threads; i++)
89 printf("output[%d] = %u\n", i, output[i]);
91 MODEL_ASSERT(in_sum == out_sum);