diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-27 08:56:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-27 08:56:39 +0100 |
| commit | f19d4b5f977a85dbab27ed9cf7c51476d1a190a6 (patch) | |
| tree | 5092e778cfc19e97d7fc2e35848e16f8740a6165 /library/std/src | |
| parent | 25db95ec4ab545e5e9569661a97a0940daa9b9ca (diff) | |
| parent | 7058f62d0a57d94eb25047741460656f1b14e566 (diff) | |
| download | rust-f19d4b5f977a85dbab27ed9cf7c51476d1a190a6.tar.gz rust-f19d4b5f977a85dbab27ed9cf7c51476d1a190a6.zip | |
Rollup merge of #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 #124466.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/thread/mod.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 59b395336f2..3f3ba02361c 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1739,7 +1739,16 @@ 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() + Arc::get_mut(&mut self.packet) + // FIXME(fuzzypixelz): returning an error instead of panicking here + // would require updating the documentation of + // `std::thread::Result`; currently we can return `Err` if and only + // if the thread had panicked. + .expect("threads should not terminate unexpectedly") + .result + .get_mut() + .take() + .unwrap() } } |
