The CDSSpec checker's benchmarks
[model-checker-benchmarks.git] / mpmc-queue / testcase1.cc
1 #include <threads.h>
2 #include <unistd.h>
3 #include <librace.h>
4
5 #include "mpmc-queue.h"
6
7 atomic_int x;
8
9 void threadA(struct mpmc_boundq_1_alt<int32_t> *queue)
10 {
11         int32_t *bin = write_prepare(queue);
12         //store_32(bin, 1);
13         write_publish(queue, bin);
14 }
15
16 void threadB(struct mpmc_boundq_1_alt<int32_t> *queue)
17 {
18         int32_t *bin;
19         if ((bin = read_fetch(queue)) != NULL) {
20                 //printf("Read: %d\n", load_32(bin));
21                 read_consume(queue, bin);
22         }
23 }
24
25 void threadC(struct mpmc_boundq_1_alt<int32_t> *queue)
26 {
27         int32_t *bin = write_prepare(queue);
28         //store_32(bin, 1);
29         write_publish(queue, bin);
30
31         while ((bin = read_fetch(queue)) != NULL) {
32                 //printf("Read: %d\n", load_32(bin));
33                 read_consume(queue, bin);
34         }
35 }
36
37
38 int user_main(int argc, char **argv)
39 {
40         mpmc_boundq_1_alt<int32_t> *queue = createMPMC(2);
41         thrd_t A, B, C;
42         /** @Entry */
43         x.store(0);
44         printf("Start threads\n");
45
46         thrd_create(&A, (thrd_start_t)&threadA, queue);
47         thrd_create(&B, (thrd_start_t)&threadB, queue);
48         //thrd_create(&C, (thrd_start_t)&threadC, queue);
49
50         thrd_join(A);
51         thrd_join(B);
52         //thrd_join(C);
53
54         printf("Threads complete\n");
55
56         destroyMPMC(queue);
57         return 0;
58 }