From 49ee9f3f08ba4583bc722a663e43551067ace271 Mon Sep 17 00:00:00 2001 From: lukaramu Date: Thu, 24 Aug 2017 17:33:36 +0200 Subject: Fix inconsistent doc headings This fixes headings reading "Unsafety" and "Example", they should be "Safety" and "Examples" according to RFC 1574. --- src/libstd/thread/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd/thread') diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index ee103c803f5..6354e746af2 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -807,7 +807,7 @@ pub fn park_timeout_ms(ms: u32) { /// Platforms which do not support nanosecond precision for sleeping will have /// `dur` rounded up to the nearest granularity of time they can sleep for. /// -/// # Example +/// # Examples /// /// Waiting for the complete expiration of the timeout: /// -- cgit 1.4.1-3-g733a5 From dc7c7ba0c9f401f5597a245e05ee9e8d760715d3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 26 Aug 2017 19:36:46 -0700 Subject: std: Handle OS errors when joining threads Also add to the documentation that the `join` method can panic. cc #34971 cc #43539 --- src/libstd/sys/unix/thread.rs | 3 ++- src/libstd/sys/windows/c.rs | 1 + src/libstd/sys/windows/thread.rs | 6 +++++- src/libstd/thread/mod.rs | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/libstd/thread') 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() { diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index ee103c803f5..195a02ae537 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1230,6 +1230,11 @@ impl JoinHandle { /// [`Err`]: ../../std/result/enum.Result.html#variant.Err /// [`panic`]: ../../std/macro.panic.html /// + /// # Panics + /// + /// This function may panic on some platforms if a thread attempts to join + /// itself or otherwise may create a deadlock with joining threads. + /// /// # Examples /// /// ``` -- cgit 1.4.1-3-g733a5