@@ -1293,6 +1293,23 @@ impl<'scope, T> Drop for Packet<'scope, T> {
1293
1293
// panicked, and nobody consumed the panic payload, we make sure
1294
1294
// the scope function will panic.
1295
1295
let unhandled_panic = matches ! ( self . result. get_mut( ) , Some ( Err ( _) ) ) ;
1296
+ // Drop the result before decrementing the number of running
1297
+ // threads, because the Drop implementation might still use things
1298
+ // it borrowed from 'scope.
1299
+ // This is only relevant for threads that aren't join()ed, as
1300
+ // join() will take the `result` and set it to None, such that
1301
+ // there is nothing left to drop here.
1302
+ // If this drop panics, that just results in an abort, because
1303
+ // we're outside of the outermost `catch_unwind` of our thread.
1304
+ // The same happens for detached non-scoped threads when dropping
1305
+ // their ignored return value (or panic payload) panics, so
1306
+ // there's no need to try to do anything better.
1307
+ // (And even if we tried to handle it, we'd also need to handle
1308
+ // the case where the panic payload we get out of it also panics
1309
+ // on drop, and so on. See issue #86027.)
1310
+ * self . result . get_mut ( ) = None ;
1311
+ // Now that there will be no more user code running on this thread
1312
+ // that can use 'scope, mark the thread as 'finished'.
1296
1313
scope. decrement_num_running_threads ( unhandled_panic) ;
1297
1314
}
1298
1315
}
0 commit comments