Skip to content

Commit 3d5d03e

Browse files
committed
Switch build_scoped to std::thread::scope (Rust 1.63)
(cherry picked from commit e39b730)
1 parent b56511f commit 3d5d03e

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
@@ -309,12 +309,12 @@ where
309309
impl ThreadPoolBuilder {
310310
/// Creates a scoped `ThreadPool` initialized using this configuration.
311311
///
312-
/// This is a convenience function for building a pool using [`crossbeam::scope`]
312+
/// This is a convenience function for building a pool using [`std::thread::scope`]
313313
/// to spawn threads in a [`spawn_handler`](#method.spawn_handler).
314314
/// The threads in this pool will start by calling `wrapper`, which should
315315
/// do initialization and continue by calling `ThreadBuilder::run()`.
316316
///
317-
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
317+
/// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html
318318
///
319319
/// # Examples
320320
///
@@ -349,18 +349,17 @@ impl ThreadPoolBuilder {
349349
W: Fn(ThreadBuilder) + Sync, // expected to call `run()`
350350
F: FnOnce(&ThreadPool) -> R,
351351
{
352-
let result = crossbeam_utils::thread::scope(|scope| {
353-
let wrapper = &wrapper;
352+
std::thread::scope(|scope| {
354353
let pool = self
355354
.spawn_handler(|thread| {
356-
let mut builder = scope.builder();
355+
let mut builder = std::thread::Builder::new();
357356
if let Some(name) = thread.name() {
358357
builder = builder.name(name.to_string());
359358
}
360359
if let Some(size) = thread.stack_size() {
361360
builder = builder.stack_size(size);
362361
}
363-
builder.spawn(move |_| wrapper(thread))?;
362+
builder.spawn_scoped(scope, || wrapper(thread))?;
364363
Ok(())
365364
})
366365
.build()?;
@@ -370,12 +369,7 @@ impl ThreadPoolBuilder {
370369
Ok(result) => Ok(result),
371370
Err(err) => unwind::resume_unwinding(err),
372371
}
373-
});
374-
375-
match result {
376-
Ok(result) => result,
377-
Err(err) => unwind::resume_unwinding(err),
378-
}
372+
})
379373
}
380374
}
381375

@@ -384,13 +378,11 @@ impl<S> ThreadPoolBuilder<S> {
384378
///
385379
/// Note that the threads will not exit until after the pool is dropped. It
386380
/// is up to the caller to wait for thread termination if that is important
387-
/// for any invariants. For instance, threads created in [`crossbeam::scope`]
381+
/// for any invariants. For instance, threads created in [`std::thread::scope`]
388382
/// will be joined before that scope returns, and this will block indefinitely
389383
/// if the pool is leaked. Furthermore, the global thread pool doesn't terminate
390384
/// until the entire process exits!
391385
///
392-
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
393-
///
394386
/// # Examples
395387
///
396388
/// A minimal spawn handler just needs to call `run()` from an independent thread.
@@ -439,6 +431,7 @@ impl<S> ThreadPoolBuilder<S> {
439431
/// or [`std::thread::scope`] introduced in Rust 1.63, which is encapsulated in
440432
/// [`build_scoped`](#method.build_scoped).
441433
///
434+
/// [`crossbeam::scope`]: https://docs.rs/crossbeam/0.8/crossbeam/fn.scope.html
442435
/// [`std::thread::scope`]: https://doc.rust-lang.org/std/thread/fn.scope.html
443436
///
444437
/// ```

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)