about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-05-03 18:34:04 -0400
committerGitHub <noreply@github.com>2017-05-03 18:34:04 -0400
commite20b2823303ddb145ce58286abeb67d4c017ccf0 (patch)
tree22c1668ffe3d91b200ce5cc3feaabcca15172188 /src/liballoc
parenta7c8bd149a88fb4cc502d59c8b29e04c780b3a10 (diff)
parent7b05b88ce799fdba12caf6ba4e6419d3dc4702f6 (diff)
downloadrust-e20b2823303ddb145ce58286abeb67d4c017ccf0.tar.gz
rust-e20b2823303ddb145ce58286abeb67d4c017ccf0.zip
Rollup merge of #41730 - bholley:arc_comment, r=aturon
Document the reasoning for the Acquire/Release handshake when dropping Arcs.

Split out from #41714. r? @aturon
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 182a107e3f7..1df79074d3f 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -767,7 +767,18 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
         // > through this reference must obviously happened before), and an
         // > "acquire" operation before deleting the object.
         //
+        // In particular, while the contents of an Arc are usually immutable, it's
+        // possible to have interior writes to something like a Mutex<T>. Since a
+        // Mutex is not acquired when it is deleted, we can't rely on its
+        // synchronization logic to make writes in thread A visible to a destructor
+        // running in thread B.
+        //
+        // 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].
+        //
         // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
+        // [2]: (https://github.com/rust-lang/rust/pull/41714)
         atomic::fence(Acquire);
 
         unsafe {