Move rare overflow error to a cold function

This commit is contained in:
Kornel 2024-04-11 22:09:43 +01:00
parent 0e5f520788
commit 1170d73007

View File

@ -47,10 +47,16 @@ pub(super) fn increment_num_running_threads(&self) {
// 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);