Description
#41730 and previous changes added comments describing the reasoning for the Acquire
fence synchronizing with the Release
counter decrement before the content of Arc
is deallocated. It refers to Boost documentation as an authoritative source. Unfortunately, even that gets its wrong: there is nothing in the C11/C++ standards (which LLVM adheres to) that guarantees ordering of non-atomic operations in presence of atomic fences. The fences in the current implementation may still be needed to e.g. order operations between strong and weak counts. However, the burden of ensuring that a newly allocated data block cannot be accessed by other threads which use past allocations at the same location lies entirely on the allocator.
The documentation of Alloc
and GlobalAlloc
may also need to be updated with the obligation to provide this guarantee for the implementations of thread-safe allocators.