9 static int iterations = 1;
10 static queue_t *queue;
11 static thrd_t *threads;
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)
25 static void parse_args(int argc, char **argv)
30 while ((c = getopt(argc, argv, "i:p:")) != EOF) {
33 iterations = atoi(optarg);
44 static void main_task(void *param)
48 int pid = *((int *)param);
50 for (i = 0; i < iterations; i++) {
51 val = 1 + pid * iterations + i;
52 printf("worker %d, enqueueing: %u\n", pid, val);
56 printf("worker %d, dequeued: %u\n", pid, val);
60 int user_main(int argc, char **argv)
65 parse_args(argc, argv);
67 queue = calloc(1, sizeof(*queue));
71 threads = malloc(num_threads * sizeof(thrd_t));
72 param = malloc(num_threads * sizeof(*param));
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]);