about summary refs log tree commit diff
path: root/library/std/src/thread/mod.rs
diff options
context:
space:
mode:
authorMahmoud Mazouz <mazouz.mahmoud@outlook.com>2025-02-23 12:22:52 +0100
committerMahmoud Mazouz <mazouz.mahmoud@outlook.com>2025-02-23 12:26:16 +0100
commitdb1f0d045887e8046dd542e119b27773991039b6 (patch)
treebd726b9d6391ecdfe414f857c527a4f458089080 /library/std/src/thread/mod.rs
parentbb2cc59a2172d6e35c89b409a4e6b5058d9039d7 (diff)
downloadrust-db1f0d045887e8046dd542e119b27773991039b6.tar.gz
rust-db1f0d045887e8046dd542e119b27773991039b6.zip
Return error on unexpected termination in `Thread::join`.
There is a time window during which the OS can terminate a thread before stdlib
can retreive its `Packet`. Currently the `Thread::join` panics with no message
in such an event, which makes debugging difficult; fixes #124466.
Diffstat (limited to 'library/std/src/thread/mod.rs')
-rw-r--r--library/std/src/thread/mod.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 59b395336f2..f5101a66ce1 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -1739,7 +1739,11 @@ struct JoinInner<'scope, T> {
 impl<'scope, T> JoinInner<'scope, T> {
     fn join(mut self) -> Result<T> {
         self.native.join();
-        Arc::get_mut(&mut self.packet).unwrap().result.get_mut().take().unwrap()
+        if let Some(packet) = Arc::get_mut(&mut self.packet) {
+            packet.result.get_mut().take().unwrap()
+        } else {
+            Err(Box::new("thread terminated unexpectedly (e.g. due to OS intervention)"))
+        }
     }
 }