From 0fd5c37563d7f3dd84b49769f496f5144cd92007 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 15 Dec 2021 11:46:39 +0000 Subject: [PATCH] Change MPSCQ to use acquire TSAN complained that there was a race that after some thoughts appears to be due to this exchange needing to be an `acquire`. I still wonder if the data dependence that is threaded through the exchange induces enough order. --- src/mem/remoteallocator.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mem/remoteallocator.h b/src/mem/remoteallocator.h index 6e33b58..b9b1ff6 100644 --- a/src/mem/remoteallocator.h +++ b/src/mem/remoteallocator.h @@ -106,9 +106,12 @@ namespace snmalloc invariant(); freelist::Object::atomic_store_null(last, key); - // exchange needs to be a release, so nullptr in next is visible. + // Exchange needs to be acq_rel. + // * It needs to be a release, so nullptr in next is visible. + // * Needs to be acquire, so linking into the list does not race with + // the other threads nullptr init of the next field. freelist::QueuePtr prev = - back.exchange(capptr_rewild(last), std::memory_order_release); + back.exchange(capptr_rewild(last), std::memory_order_acq_rel); freelist::Object::atomic_store_next(domesticate_head(prev), first, key); }