Skip to content

Commit 61fdd3e

Browse files
committed
expand comment on default mutex behavior
1 parent 6318d24 commit 61fdd3e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/libstd/sys/unix/mutex.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ impl Mutex {
2828
//
2929
// A pthread mutex initialized with PTHREAD_MUTEX_INITIALIZER will have
3030
// a type of PTHREAD_MUTEX_DEFAULT, which has undefined behavior if you
31-
// try to re-lock it from the same thread when you already hold a lock.
31+
// try to re-lock it from the same thread when you already hold a lock
32+
// (https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html).
3233
//
3334
// In practice, glibc takes advantage of this undefined behavior to
3435
// implement hardware lock elision, which uses hardware transactional
35-
// memory to avoid acquiring the lock. While a transaction is in
36+
// memory to avoid acquiring the lock.
37+
// This is the case even if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL
38+
// (https://github.com/rust-lang/rust/issues/33770#issuecomment-220847521).
39+
// As a consequence, while a transaction is in
3640
// progress, the lock appears to be unlocked. This isn't a problem for
3741
// other threads since the transactional memory will abort if a conflict
38-
// is detected, however no abort is generated if re-locking from the
42+
// is detected, however no abort is generated when re-locking from the
3943
// same thread.
4044
//
4145
// Since locking the same mutex twice will result in two aliasing &mut

0 commit comments

Comments
 (0)