Skip to content

Commit 80f8285

Browse files
committed
std: add comment explaining lock result check
1 parent 5fae61e commit 80f8285

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/std/src/sys/pal/unix/locks/pthread_mutex.rs

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ impl Mutex {
112112
}
113113

114114
let r = libc::pthread_mutex_lock(raw(self));
115+
// As we set the mutex type to `PTHREAD_MUTEX_NORMAL` above, we expect
116+
// the lock call to never fail. Unfortunately however, some platforms
117+
// (Solaris) do not conform to the standard, and instead always provide
118+
// deadlock detection. How kind of them! Unfortunately that means that
119+
// we need to check the error code here. To save use from UB on other
120+
// less well-behaved platforms in the future, we do it even on "good"
121+
// platforms like macOS. See #120147 for more context.
115122
if r != 0 {
116123
fail()
117124
}

0 commit comments

Comments
 (0)