about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-05-04 19:17:58 +0200
committerRalf Jung <post@ralfj.de>2020-05-04 19:17:58 +0200
commit61fdd3e2bee1ea0f517ff0bfe16f3816decab99a (patch)
treee20e7b0ce539bf57e3891bf2f65fd70f07f42f19 /src/libstd/sys
parent6318d24ad8440fa30428b405be1174478e9536e3 (diff)
downloadrust-61fdd3e2bee1ea0f517ff0bfe16f3816decab99a.tar.gz
rust-61fdd3e2bee1ea0f517ff0bfe16f3816decab99a.zip
expand comment on default mutex behavior
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/mutex.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index 103d87e3d2f..185615d01dd 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -28,14 +28,18 @@ impl Mutex {
         //
         // A pthread mutex initialized with PTHREAD_MUTEX_INITIALIZER will have
         // a type of PTHREAD_MUTEX_DEFAULT, which has undefined behavior if you
-        // try to re-lock it from the same thread when you already hold a lock.
+        // try to re-lock it from the same thread when you already hold a lock
+        // (https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html).
         //
         // In practice, glibc takes advantage of this undefined behavior to
         // implement hardware lock elision, which uses hardware transactional
-        // memory to avoid acquiring the lock. While a transaction is in
+        // memory to avoid acquiring the lock.
+        // This is the case even if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL
+        // (https://github.com/rust-lang/rust/issues/33770#issuecomment-220847521).
+        // As a consequence, while a transaction is in
         // progress, the lock appears to be unlocked. This isn't a problem for
         // other threads since the transactional memory will abort if a conflict
-        // is detected, however no abort is generated if re-locking from the
+        // is detected, however no abort is generated when re-locking from the
         // same thread.
         //
         // Since locking the same mutex twice will result in two aliasing &mut