From de000bbe819490f00d335767325fa41c254b92ea Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 26 Jan 2024 16:25:49 -0800 Subject: [PATCH] Let the octillion test use more threads --- tests/octillion.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/octillion.rs b/tests/octillion.rs index 1af9ad8ba..9540f0b5f 100644 --- a/tests/octillion.rs +++ b/tests/octillion.rs @@ -61,10 +61,17 @@ fn two_threads R, R: Send>(f: F) -> R { // FIXME: If we don't use at least two threads, then we end up walking // through the entire iterator sequentially, without the benefit of any // short-circuiting. We probably don't want testing to wait that long. ;) - let builder = rayon::ThreadPoolBuilder::new().num_threads(2); - let pool = builder.build().unwrap(); - - pool.install(f) + if rayon::current_num_threads() < 2 { + use std::sync::OnceLock; + static POOL: OnceLock = OnceLock::new(); + let pool = POOL.get_or_init(|| { + let builder = rayon::ThreadPoolBuilder::new().num_threads(2); + builder.build().unwrap() + }); + pool.install(f) + } else { + f() + } } #[test]