From c4630c872112636823aaf512e0c8b3a1e5e20d6f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 22 Jun 2022 13:41:49 -0700 Subject: [PATCH] Switch build_scoped to std::thread::scope (Rust 1.63) --- rayon-core/src/lib.rs | 23 ++++++++--------------- rayon-core/tests/scoped_threadpool.rs | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/rayon-core/src/lib.rs b/rayon-core/src/lib.rs index ac95156dc..3879b0a1d 100644 --- a/rayon-core/src/lib.rs +++ b/rayon-core/src/lib.rs @@ -265,12 +265,12 @@ where impl ThreadPoolBuilder { /// Creates a scoped `ThreadPool` initialized using this configuration. /// - /// This is a convenience function for building a pool using [`crossbeam::scope`] + /// This is a convenience function for building a pool using [`std::thread::scope`] /// to spawn threads in a [`spawn_handler`](#method.spawn_handler). /// The threads in this pool will start by calling `wrapper`, which should /// do initialization and continue by calling `ThreadBuilder::run()`. /// - /// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html + /// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html /// /// # Examples /// @@ -305,28 +305,22 @@ impl ThreadPoolBuilder { W: Fn(ThreadBuilder) + Sync, // expected to call `run()` F: FnOnce(&ThreadPool) -> R, { - let result = crossbeam_utils::thread::scope(|scope| { - let wrapper = &wrapper; + std::thread::scope(|scope| { let pool = self .spawn_handler(|thread| { - let mut builder = scope.builder(); + let mut builder = std::thread::Builder::new(); if let Some(name) = thread.name() { builder = builder.name(name.to_string()); } if let Some(size) = thread.stack_size() { builder = builder.stack_size(size); } - builder.spawn(move |_| wrapper(thread))?; + builder.spawn_scoped(scope, || wrapper(thread))?; Ok(()) }) .build()?; Ok(with_pool(&pool)) - }); - - match result { - Ok(result) => result, - Err(err) => unwind::resume_unwinding(err), - } + }) } } @@ -335,13 +329,11 @@ impl ThreadPoolBuilder { /// /// Note that the threads will not exit until after the pool is dropped. It /// is up to the caller to wait for thread termination if that is important - /// for any invariants. For instance, threads created in [`crossbeam::scope`] + /// for any invariants. For instance, threads created in [`std::thread::scope`] /// will be joined before that scope returns, and this will block indefinitely /// if the pool is leaked. Furthermore, the global thread pool doesn't terminate /// until the entire process exits! /// - /// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html - /// /// # Examples /// /// A minimal spawn handler just needs to call `run()` from an independent thread. @@ -390,6 +382,7 @@ impl ThreadPoolBuilder { /// or [`std::thread::scope`] introduced in Rust 1.63, which is encapsulated in /// [`build_scoped`](#method.build_scoped). /// + /// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html /// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html /// /// ``` diff --git a/rayon-core/tests/scoped_threadpool.rs b/rayon-core/tests/scoped_threadpool.rs index db3d0b874..2862cb15b 100644 --- a/rayon-core/tests/scoped_threadpool.rs +++ b/rayon-core/tests/scoped_threadpool.rs @@ -90,7 +90,7 @@ fn build_scoped_tls_threadpool() { }, ) .expect("thread pool created"); - // Internally, `crossbeam::scope` will wait for the threads to exit before returning. + // Internally, `std::thread::scope` will wait for the threads to exit before returning. }); }); }