Skip to content

Commit 5fae61e

Browse files
committed
std: always check the result of pthread_mutex_lock
1 parent 366d112 commit 5fae61e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::cell::UnsafeCell;
2+
use crate::io::Error;
23
use crate::mem::{forget, MaybeUninit};
34
use crate::sys::cvt_nz;
45
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
@@ -103,8 +104,17 @@ impl Mutex {
103104

104105
#[inline]
105106
pub unsafe fn lock(&self) {
107+
#[cold]
108+
#[inline(never)]
109+
fn fail() -> ! {
110+
let error = Error::last_os_error();
111+
panic!("failed to lock mutex: {error}");
112+
}
113+
106114
let r = libc::pthread_mutex_lock(raw(self));
107-
debug_assert_eq!(r, 0);
115+
if r != 0 {
116+
fail()
117+
}
108118
}
109119

110120
#[inline]

0 commit comments

Comments
 (0)