Understanding happens-before relationship in this case

⚓ Rust    📅 2026-03-13    👤 surdeus    👁️ 5      

surdeus

Acquire loading a particular value which was stored by a Release operation helps in establishing a happens-before relationship, but how exactly does this work? Does the fence create like a wait point, where it waits for all operations on the shared memory to finish after which we could finally drop the shared memory?

impl<T> Drop for Arc<T> {
    fn drop(&mut self) {
        if self.data().ref_count.fetch_sub(1, Release) == 1 {
            fence(Acquire);
            unsafe {
                drop(Box::from_raw(self.ptr.as_ptr()));
            }
        }
    }
}

2 posts - 2 participants

Read full topic

🏷️ Rust_feed