9 #include "mpmc-queue.h"
11 void threadA(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
13 int32_t *bin = queue->write_prepare();
15 queue->write_publish();
18 void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
21 while (bin = queue->read_fetch()) {
22 printf("Read: %d\n", load_32(bin));
23 queue->read_consume();
30 int readers = 2, writers = 1;
34 printf("Error: use the following options\n"
35 " -r <num> Choose number of reader threads\n"
36 " -w <num> Choose number of writer threads\n");
40 void process_params(int argc, char **argv)
42 const char *shortopts = "hr:w:";
46 while (!error && (opt = getopt(argc, argv, shortopts)) != -1) {
52 readers = atoi(optarg);
55 writers = atoi(optarg);
63 if (writers < 1 || writers > MAXWRITERS)
65 if (readers < 1 || readers > MAXREADERS)
72 int user_main(int argc, char **argv)
74 struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> queue;
75 thrd_t A[MAXWRITERS], B[MAXREADERS];
77 /* Note: optarg() / optind is broken in model-checker - workaround is
78 * to just copy&paste this test a few times */
79 //process_params(argc, argv);
80 printf("%d reader(s), %d writer(s)\n", readers, writers);
82 int32_t *bin = queue.write_prepare();
84 queue.write_publish();
86 printf("Start threads\n");
88 for (int i = 0; i < writers; i++)
89 thrd_create(&A[i], (thrd_start_t)&threadA, &queue);
90 for (int i = 0; i < readers; i++)
91 thrd_create(&B[i], (thrd_start_t)&threadB, &queue);
93 for (int i = 0; i < writers; i++)
95 for (int i = 0; i < readers; i++)
98 printf("Threads complete\n");