Skip to content

Commit db1f0d0

Browse files
committed
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 rust-lang#124466.
1 parent bb2cc59 commit db1f0d0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: library/std/src/thread/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,11 @@ struct JoinInner<'scope, T> {
17391739
impl<'scope, T> JoinInner<'scope, T> {
17401740
fn join(mut self) -> Result<T> {
17411741
self.native.join();
1742-
Arc::get_mut(&mut self.packet).unwrap().result.get_mut().take().unwrap()
1742+
if let Some(packet) = Arc::get_mut(&mut self.packet) {
1743+
packet.result.get_mut().take().unwrap()
1744+
} else {
1745+
Err(Box::new("thread terminated unexpectedly (e.g. due to OS intervention)"))
1746+
}
17431747
}
17441748
}
17451749

0 commit comments

Comments
 (0)