Skip to content

Commit 3758e2f

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 41a294d + 1170d73 commit 3758e2f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

library/std/src/thread/scoped.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ impl ScopeData {
4747
// chance it overflows to 0, which would result in unsoundness.
4848
if self.num_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
4949
// This can only reasonably happen by mem::forget()'ing a lot of ScopedJoinHandles.
50-
self.decrement_num_running_threads(false);
51-
panic!("too many running threads in thread scope");
50+
self.overflow();
5251
}
5352
}
53+
54+
#[cold]
55+
fn overflow(&self) {
56+
self.decrement_num_running_threads(false);
57+
panic!("too many running threads in thread scope");
58+
}
59+
5460
pub(super) fn decrement_num_running_threads(&self, panic: bool) {
5561
if panic {
5662
self.a_thread_panicked.store(true, Ordering::Relaxed);

0 commit comments

Comments
 (0)