diff --git a/halfhalf.c b/halfhalf.c index 31d050a..ce9fb17 100644 --- a/halfhalf.c +++ b/halfhalf.c @@ -3,6 +3,7 @@ #include #include "delay.h" #include "queue.h" +#include "primitives.h" #ifndef LOGN_OPS #define LOGN_OPS 7 @@ -37,7 +38,10 @@ void thread_init(int id, int nprocs) { } void thread_exit(int id, int nprocs) { - queue_free(q, hds[id]); + // Only free the queue from a single thread, to avoid double-free + static int lock = 0; + if (FAA(&lock, 1) == 0) + queue_free(q, hds[id]); } void * benchmark(int id, int nprocs) { diff --git a/pairwise.c b/pairwise.c index 2244b17..74e66a6 100644 --- a/pairwise.c +++ b/pairwise.c @@ -3,6 +3,7 @@ #include #include "delay.h" #include "queue.h" +#include "primitives.h" #ifndef LOGN_OPS #define LOGN_OPS 7 @@ -57,7 +58,10 @@ void * benchmark(int id, int nprocs) { } void thread_exit(int id, int nprocs) { - queue_free(q, hds[id]); + // Only free the queue from a single thread, to avoid double-free + static int lock = 0; + if (FAA(&lock, 1) == 0) + queue_free(q, hds[id]); } #ifdef VERIFY