No Atomic - Fence synchronization in Rust?

⚓ Rust    📅 2025-10-17    👤 surdeus    👁️ 2      

surdeus

Prompted by a post on r/cpp, I was reading the little nugget by Raymond Chen explaining the necessary memory ordering when writing one's own Arc: Why can you increment a reference count with relaxed semantics, but you have to decrement with release semantics? - The Old New Thing.

static uint32_t __stdcall Release(fast_abi_forwarder* self) noexcept
{
    uint32_t const remaining = self->m_references.
        fetch_sub(1, std::memory_order_release) - 1;

    if (remaining == 0)
    {
        std::atomic_thread_fence(std::memory_order_acquire);
        delete self;
    }

    return remaining;
}

This is using atomic - fence synchronization, one of the 3 synchronization modes available with std::atomic_thread_fence, alongside fence - atomic and fence - fence.

This prompted me to realize that the Rust "equivalent", our own atomic::fence, only documents fence - fence synchronization.

Is this a documentation issue? Or does Rust not support atomic - fence & fence - atomic synchronizations?

I thought that Rust copied C/C++ memory model, so it's somewhat surprising (and unhelpful) to see a divergence.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed