Skip to content

Commit 7b05b88

Browse files
committedMay 3, 2017
Document the reasoning for the Acquire/Release handshake when dropping Arcs.
1 parent ed1f26d commit 7b05b88

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

‎src/liballoc/arc.rs

+11
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,18 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
767767
// > through this reference must obviously happened before), and an
768768
// > "acquire" operation before deleting the object.
769769
//
770+
// In particular, while the contents of an Arc are usually immutable, it's
771+
// possible to have interior writes to something like a Mutex<T>. Since a
772+
// Mutex is not acquired when it is deleted, we can't rely on its
773+
// synchronization logic to make writes in thread A visible to a destructor
774+
// running in thread B.
775+
//
776+
// Also note that the Acquire fence here could probably be replaced with an
777+
// Acquire load, which could improve performance in highly-contended
778+
// situations. See [2].
779+
//
770780
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
781+
// [2]: (https://github.com/rust-lang/rust/pull/41714)
771782
atomic::fence(Acquire);
772783

773784
unsafe {

0 commit comments

Comments
 (0)
Please sign in to comment.