Simplify panicking mechanism of thread::scope.
It now panic!()s on its own, rather than resume_unwind'ing the panic payload from the thread. Using resume_unwind skips the panic_handler, meaning that the main thread would never have a panic handler run, which can get confusing.
This commit is contained in:
parent
da33da161b
commit
f5217792ed
2 changed files with 22 additions and 31 deletions
|
|
@ -1286,16 +1286,13 @@ unsafe impl<'scope, T: Sync> Sync for Packet<'scope, T> {}
|
|||
|
||||
impl<'scope, T> Drop for Packet<'scope, T> {
|
||||
fn drop(&mut self) {
|
||||
// Book-keeping so the scope knows when it's done.
|
||||
if let Some(scope) = self.scope {
|
||||
// If this packet was for a thread that ran in a scope, the thread
|
||||
// panicked, and nobody consumed the panic payload, we put the
|
||||
// panic payload in the scope so it can re-throw it, if it didn't
|
||||
// already capture any panic yet.
|
||||
if let Some(Err(e)) = self.result.get_mut().take() {
|
||||
scope.panic_payload.lock().unwrap().get_or_insert(e);
|
||||
}
|
||||
// Book-keeping so the scope knows when it's done.
|
||||
scope.decrement_n_running_threads();
|
||||
// panicked, and nobody consumed the panic payload, we make sure
|
||||
// the scope function will panic.
|
||||
let unhandled_panic = matches!(self.result.get_mut(), Some(Err(_)));
|
||||
scope.decrement_n_running_threads(unhandled_panic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue