Skip to content

Commit e39b730

Browse files
committed
Switch build_scoped to std::thread::scope (Rust 1.63)
1 parent 63b959c commit e39b730

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

rayon-core/src/lib.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ where
284284
impl ThreadPoolBuilder {
285285
/// Creates a scoped `ThreadPool` initialized using this configuration.
286286
///
287-
/// This is a convenience function for building a pool using [`crossbeam::scope`]
287+
/// This is a convenience function for building a pool using [`std::thread::scope`]
288288
/// to spawn threads in a [`spawn_handler`](#method.spawn_handler).
289289
/// The threads in this pool will start by calling `wrapper`, which should
290290
/// do initialization and continue by calling `ThreadBuilder::run()`.
291291
///
292-
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
292+
/// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html
293293
///
294294
/// # Examples
295295
///
@@ -324,28 +324,22 @@ impl ThreadPoolBuilder {
324324
W: Fn(ThreadBuilder) + Sync, // expected to call `run()`
325325
F: FnOnce(&ThreadPool) -> R,
326326
{
327-
let result = crossbeam_utils::thread::scope(|scope| {
328-
let wrapper = &wrapper;
327+
std::thread::scope(|scope| {
329328
let pool = self
330329
.spawn_handler(|thread| {
331-
let mut builder = scope.builder();
330+
let mut builder = std::thread::Builder::new();
332331
if let Some(name) = thread.name() {
333332
builder = builder.name(name.to_string());
334333
}
335334
if let Some(size) = thread.stack_size() {
336335
builder = builder.stack_size(size);
337336
}
338-
builder.spawn(move |_| wrapper(thread))?;
337+
builder.spawn_scoped(scope, || wrapper(thread))?;
339338
Ok(())
340339
})
341340
.build()?;
342341
Ok(with_pool(&pool))
343-
});
344-
345-
match result {
346-
Ok(result) => result,
347-
Err(err) => unwind::resume_unwinding(err),
348-
}
342+
})
349343
}
350344
}
351345

@@ -354,13 +348,11 @@ impl<S> ThreadPoolBuilder<S> {
354348
///
355349
/// Note that the threads will not exit until after the pool is dropped. It
356350
/// is up to the caller to wait for thread termination if that is important
357-
/// for any invariants. For instance, threads created in [`crossbeam::scope`]
351+
/// for any invariants. For instance, threads created in [`std::thread::scope`]
358352
/// will be joined before that scope returns, and this will block indefinitely
359353
/// if the pool is leaked. Furthermore, the global thread pool doesn't terminate
360354
/// until the entire process exits!
361355
///
362-
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
363-
///
364356
/// # Examples
365357
///
366358
/// A minimal spawn handler just needs to call `run()` from an independent thread.
@@ -409,6 +401,7 @@ impl<S> ThreadPoolBuilder<S> {
409401
/// or [`std::thread::scope`] introduced in Rust 1.63, which is encapsulated in
410402
/// [`build_scoped`](#method.build_scoped).
411403
///
404+
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
412405
/// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html
413406
///
414407
/// ```

rayon-core/tests/scoped_threadpool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn build_scoped_tls_threadpool() {
9393
},
9494
)
9595
.expect("thread pool created");
96-
// Internally, `crossbeam::scope` will wait for the threads to exit before returning.
96+
// Internally, `std::thread::scope` will wait for the threads to exit before returning.
9797
});
9898
});
9999
}

0 commit comments

Comments
 (0)