mpmc-queue: driver fixes
authorBrian Norris <banorris@uci.edu>
Wed, 10 Oct 2012 23:15:56 +0000 (16:15 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 10 Oct 2012 23:15:56 +0000 (16:15 -0700)
* Initialize queue with at least one item

* Instrument some racy accesses in driver

* Print a little information to see what kind of loops we're stuck in

mpmc-queue/mpmc-queue.cc

index b6af7ef..146f11e 100644 (file)
@@ -1,3 +1,4 @@
+#include <inttypes.h>
 #include <threads.h>
 #include <stdio.h>
 
@@ -5,29 +6,37 @@
 
 #include "mpmc-queue.h"
 
-void threadA(struct mpmc_boundq_1_alt<int, sizeof(int)> *queue)
+void threadA(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
 {
-       int *bin = queue->write_prepare();
-       *bin = 1;
+       int32_t *bin = queue->write_prepare();
+       store_32(bin, 1);
        queue->write_publish();
 }
 
-void threadB(struct mpmc_boundq_1_alt<int, sizeof(int)> *queue)
+void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
 {
-       int *bin = queue->read_fetch();
-       printf("Read: %d\n", *bin);
+       int32_t *bin = queue->read_fetch();
+       printf("Read: %d\n", load_32(bin));
        queue->read_consume();
 }
 
 int user_main(int argc, char **argv)
 {
-       struct mpmc_boundq_1_alt<int, sizeof(int)> queue;
+       struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> queue;
        thrd_t A, B;
 
+       int32_t *bin = queue.write_prepare();
+       store_32(bin, 17);
+       queue.write_publish();
+
+       printf("Start threads\n");
+
        thrd_create(&A, (thrd_start_t)&threadA, &queue);
        thrd_create(&B, (thrd_start_t)&threadB, &queue);
        thrd_join(A);
        thrd_join(B);
 
+       printf("Threads complete\n");
+
        return 0;
 }