mcs-lock: add more locking tests to driver
[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;
19         while (bin = queue->read_fetch()) {
20                 printf("Read: %d\n", load_32(bin));
21                 queue->read_consume();
22         }
23 }
24
25 int user_main(int argc, char **argv)
26 {
27         struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> queue;
28         thrd_t A, B;
29
30         int32_t *bin = queue.write_prepare();
31         store_32(bin, 17);
32         queue.write_publish();
33
34         printf("Start threads\n");
35
36         thrd_create(&A, (thrd_start_t)&threadA, &queue);
37         thrd_create(&B, (thrd_start_t)&threadB, &queue);
38         thrd_join(A);
39         thrd_join(B);
40
41         printf("Threads complete\n");
42
43         return 0;
44 }