mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #123826 - kornelski:one-in-a-quintillion, r=Amanieu
Move rare overflow error to a cold function `scoped.spawn()` generates unnecessary inlined panic-formatting code for a branch that will never be taken.
This commit is contained in:
commit
3758e2ffa5
@ -47,10 +47,16 @@ impl ScopeData {
|
|||||||
// chance it overflows to 0, which would result in unsoundness.
|
// chance it overflows to 0, which would result in unsoundness.
|
||||||
if self.num_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
|
if self.num_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
|
||||||
// This can only reasonably happen by mem::forget()'ing a lot of ScopedJoinHandles.
|
// This can only reasonably happen by mem::forget()'ing a lot of ScopedJoinHandles.
|
||||||
self.decrement_num_running_threads(false);
|
self.overflow();
|
||||||
panic!("too many running threads in thread scope");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cold]
|
||||||
|
fn overflow(&self) {
|
||||||
|
self.decrement_num_running_threads(false);
|
||||||
|
panic!("too many running threads in thread scope");
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn decrement_num_running_threads(&self, panic: bool) {
|
pub(super) fn decrement_num_running_threads(&self, panic: bool) {
|
||||||
if panic {
|
if panic {
|
||||||
self.a_thread_panicked.store(true, Ordering::Relaxed);
|
self.a_thread_panicked.store(true, Ordering::Relaxed);
|
||||||
|
Loading…
Reference in New Issue
Block a user