diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-26 19:36:46 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-08-26 19:36:46 -0700 |
| commit | dc7c7ba0c9f401f5597a245e05ee9e8d760715d3 (patch) | |
| tree | 3368e960243d97ec04df19b3b7e51653913baaac /src/libstd/sys | |
| parent | 398aaffc94367ed59420f5ac0b0238c04c9e4fa5 (diff) | |
| download | rust-dc7c7ba0c9f401f5597a245e05ee9e8d760715d3.tar.gz rust-dc7c7ba0c9f401f5597a245e05ee9e8d760715d3.zip | |
std: Handle OS errors when joining threads
Also add to the documentation that the `join` method can panic. cc #34971 cc #43539
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/windows/c.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 15747746611..40f1d6a6db1 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -168,7 +168,8 @@ impl Thread { unsafe { let ret = libc::pthread_join(self.id, ptr::null_mut()); mem::forget(self); - debug_assert_eq!(ret, 0); + assert!(ret == 0, + "failed to join thread: {}", io::Error::from_raw_os_error(ret)); } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index ba54ca6ea18..7dfcc996e18 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -273,6 +273,7 @@ pub const FILE_END: DWORD = 2; pub const WAIT_OBJECT_0: DWORD = 0x00000000; pub const WAIT_TIMEOUT: DWORD = 258; +pub const WAIT_FAILED: DWORD = 0xFFFFFFFF; #[cfg(target_env = "msvc")] pub const MAX_SYM_NAME: usize = 2000; diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 5a376a867ee..2cdd86e88b0 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -61,7 +61,11 @@ impl Thread { } pub fn join(self) { - unsafe { c::WaitForSingleObject(self.handle.raw(), c::INFINITE); } + let rc = unsafe { c::WaitForSingleObject(self.handle.raw(), c::INFINITE) }; + if rc == c::WAIT_FAILED { + panic!("failed to join on thread: {}", + io::Error::last_os_error()); + } } pub fn yield_now() { |
