mpmc-queue: driver fixes
[model-checker-benchmarks.git] / mpmc-queue / mpmc-queue.cc
1 #include <inttypes.h>
2 #include <threads.h>
3 #include <stdio.h>
4
5 #include <librace.h>
6
7 #include "mpmc-queue.h"
8
9 void threadA(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
10 {
11         int32_t *bin = queue->write_prepare();
12         store_32(bin, 1);
13         queue->write_publish();
14 }
15
16 void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
17 {
18         int32_t *bin = queue->read_fetch();
19         printf("Read: %d\n", load_32(bin));
20         queue->read_consume();
21 }
22
23 int user_main(int argc, char **argv)
24 {
25         struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> queue;
26         thrd_t A, B;
27
28         int32_t *bin = queue.write_prepare();
29         store_32(bin, 17);
30         queue.write_publish();
31
32         printf("Start threads\n");
33
34         thrd_create(&A, (thrd_start_t)&threadA, &queue);
35         thrd_create(&B, (thrd_start_t)&threadB, &queue);
36         thrd_join(A);
37         thrd_join(B);
38
39         printf("Threads complete\n");
40
41         return 0;
42 }