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