diff options
| author | Kornel <kornel@geekhood.net> | 2024-04-11 22:09:43 +0100 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2024-04-11 22:23:49 +0100 |
| commit | 1170d73007c1547dc07dadf247bb74bff4c35294 (patch) | |
| tree | bf3c7435b3047ee06150ccb6fefdc749807be3c6 | |
| parent | 0e5f5207881066973486e6a480fa46cfa22947e9 (diff) | |
| download | rust-1170d73007c1547dc07dadf247bb74bff4c35294.tar.gz rust-1170d73007c1547dc07dadf247bb74bff4c35294.zip | |
Move rare overflow error to a cold function
| -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); |
