diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-12 04:38:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-12 04:38:22 +0200 |
| commit | 3758e2ffa5f14d1cb50ff6d1436489bb3749f627 (patch) | |
| tree | c3c466cf5db9cde81d9d8cc631f86428f41f4cd4 | |
| parent | 41a294dd2be3279682b59b189beb60d18d70bfa7 (diff) | |
| parent | 1170d73007c1547dc07dadf247bb74bff4c35294 (diff) | |
| download | rust-3758e2ffa5f14d1cb50ff6d1436489bb3749f627.tar.gz rust-3758e2ffa5f14d1cb50ff6d1436489bb3749f627.zip | |
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.
| -rw-r--r-- | library/std/src/thread/scoped.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/library/std/src/thread/scoped.rs b/library/std/src/thread/scoped.rs index 7b11e7c17b1..e2e22e5194f 100644 --- a/library/std/src/thread/scoped.rs +++ b/library/std/src/thread/scoped.rs @@ -47,10 +47,16 @@ impl ScopeData { // chance it overflows to 0, which would result in unsoundness. 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. - self.decrement_num_running_threads(false); - panic!("too many running threads in thread scope"); + self.overflow(); } } + + #[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) { if panic { self.a_thread_panicked.store(true, Ordering::Relaxed); |
