X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=mpmc-queue%2Fmpmc-queue.cc;h=741811aaf357578bc0d0056d4ce4272f66881dc8;hp=b6af7ef7020f8f5f02812701d8eea07e99663c0f;hb=40b27f40998eed81640b016094bacf79df96d377;hpb=1ac0b596891b03e2b3651ed78252294ca02e928a diff --git a/mpmc-queue/mpmc-queue.cc b/mpmc-queue/mpmc-queue.cc index b6af7ef..741811a 100644 --- a/mpmc-queue/mpmc-queue.cc +++ b/mpmc-queue/mpmc-queue.cc @@ -1,3 +1,4 @@ +#include #include #include @@ -5,29 +6,43 @@ #include "mpmc-queue.h" -void threadA(struct mpmc_boundq_1_alt *queue) +void threadA(struct mpmc_boundq_1_alt *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 *queue) +void threadB(struct mpmc_boundq_1_alt *queue) { - int *bin = queue->read_fetch(); - printf("Read: %d\n", *bin); - queue->read_consume(); + int32_t *bin; + while (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 queue; - thrd_t A, B; + struct mpmc_boundq_1_alt queue; + thrd_t A1, A2, B1, B2; - thrd_create(&A, (thrd_start_t)&threadA, &queue); - thrd_create(&B, (thrd_start_t)&threadB, &queue); - thrd_join(A); - thrd_join(B); + int32_t *bin = queue.write_prepare(); + store_32(bin, 17); + queue.write_publish(); + + printf("Start threads\n"); + + thrd_create(&A1, (thrd_start_t)&threadA, &queue); + thrd_create(&A2, (thrd_start_t)&threadA, &queue); + thrd_create(&B1, (thrd_start_t)&threadB, &queue); + thrd_create(&B2, (thrd_start_t)&threadB, &queue); + thrd_join(A1); + thrd_join(A2); + thrd_join(B1); + thrd_join(B2); + + printf("Threads complete\n"); return 0; }