Skip to content

Commit 3e88f40

Browse files
authored
Rollup merge of rust-lang#137480 - fuzzypixelz:fix/124466, r=workingjubilee
Return unexpected termination error instead of panicing 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.
2 parents 55073e8 + 7058f62 commit 3e88f40

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/std/src/thread/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,16 @@ 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+
Arc::get_mut(&mut self.packet)
1743+
// FIXME(fuzzypixelz): returning an error instead of panicking here
1744+
// would require updating the documentation of
1745+
// `std::thread::Result`; currently we can return `Err` if and only
1746+
// if the thread had panicked.
1747+
.expect("threads should not terminate unexpectedly")
1748+
.result
1749+
.get_mut()
1750+
.take()
1751+
.unwrap()
17431752
}
17441753
}
17451754

0 commit comments

Comments
 (0)