pub(super) fn increment_n_running_threads(&self) {
// We check for 'overflow' with usize::MAX / 2, to make sure there's no
// chance it overflows to 0, which would result in unsoundness.
- if self.n_running_threads.fetch_add(1, Ordering::Relaxed) == usize::MAX / 2 {
+ if self.n_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
// This can only reasonably happen by mem::forget()'ing many many ScopedJoinHandles.
self.decrement_n_running_threads(false);
panic!("too many running threads in thread scope");
/// The function passed to `scope` will be provided a [`Scope`] object,
/// through which scoped threads can be [spawned][`Scope::spawn`].
///
-/// Unlike non-scoped threads, scoped threads can non-`'static` data,
+/// Unlike non-scoped threads, scoped threads can borrow non-`'static` data,
/// as the scope guarantees all threads will be joined at the end of the scope.
///
/// All threads spawned within the scope that haven't been manually joined
///
/// # Panics
///
- /// Panics if the OS fails to create a thread; use [`Builder::spawn`]
+ /// Panics if the OS fails to create a thread; use [`Builder::spawn_scoped`]
/// to recover from such errors.
///
/// [`join`]: ScopedJoinHandle::join
self.0.join()
}
- /// Checks if the the associated thread is still running its main function.
+ /// Checks if the associated thread is still running its main function.
///
/// This might return `false` for a brief moment after the thread's main
/// function has returned, but before the thread itself has stopped running.