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.
This commit is contained in:
Matthew Parkinson
2021-12-15 11:46:39 +00:00
committed by Matthew Parkinson
parent 7768765fe8
commit 0fd5c37563

View File

@@ -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);
}