Comment in Rustnomicon re Acquire in Arc::Drop

⚓ Rust    📅 2026-06-01    👤 surdeus    👁️ 1      

surdeus

There is an interesting remark here, which I would like to get to the bottom of:

"Also note that the Acquire fence here could probably be replaced with an Acquire load, which could improve performance in highly-contended situations. See 2."

I don't think the comment is correct. I think it shows a mis-understanding of what fence does. Specifically, although using a load with Acquire would be correct, it would not improve performance, because fence simply prevents the compiler from re-ordering operations that affect memory, and both the load and fence will do the same thing ( but a load might actually be less efficient ).

But maybe I am wrong...

I think the problem here may be that almost everyone ( certainly myself included ) is not very expert on atomics and Acquire/Release, as it is very rare that you need to know about it or use it. I have been studying it today though.

Anyway, do you think the comment is correct or not?

8 posts - 3 participants

Read full topic

🏷️ Rust_feed